www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4669] New: Unit tests do not work in libraries compiled by dmd with -lib

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4669

           Summary: Unit tests do not work in libraries compiled by dmd
                    with -lib
           Product: D
           Version: D1 & D2
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: mike.linford gmail.com



PDT ---
The following unit test in mylib.d is not run:

mylib.d:

  1 module mylib;
  2
  3 void blah()
  4 {
  5 }
  6 unittest
  7 {
  8    assert(false);
  9 }
 10

test.d:

  1 module test;
  2
  3 import mylib;
  4
  5 void main()
  6 {
  7    blah();
  8 }
  9


Makefile:
  1 test : mylib.a test.d
  2    dmd -unittest test.d mylib.a
  3
  4 mylib.a : mylib.d
  5    dmd -unittest -lib mylib.d
  6
  7 clean :
  8    rm -f test mylib.a *.o
  9

However, it WILL be run if the project is compiled as follows:

dmd -unittest -c mylib.d
ar -rc mylib.a mylib.o
dmd -unittest test.d mylib.a

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 17 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4669


Stephan Dilly <spam extrawurst.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |spam extrawurst.org



---
i can confirm that unittests in static librarys build by dmd does not get
triggered on windows too.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 17 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4669


Mike Parker <aldacron gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simendsjo gmail.com



*** Issue 6464 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 10 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4669


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



07:10:13 PDT ---
This needs more attention imho. If unittests are first-class citizens in D then
we shouldn't have to use workarounds just to trigger them in a library.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 15 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4669


PhilLavoie <maidenphil hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maidenphil hotmail.com
         OS/Version|Linux                       |Windows



---
Yeah, I also confirm this issue on Windows. Since unit testing plays an
important part in software construction, I hope that it gets the attention it
deserves and gets fixed soon :). Love D 4 Life.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 14 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4669




09:02:59 PST ---
The cause is this code in 'FuncDeclaration::toObjFile':

if (multiobj && !isStaticDtorDeclaration() && !isStaticCtorDeclaration())
{   obj_append(this);
    return;
}

'multiobj' is true when -lib is passed, this unittest is then deferred to be
generated later (and it *is* generated later), however it never seems to be
run.

Anyway a qujick fix is to add a check for lib generation:

if (multiobj && !global.params.lib && !isStaticDtorDeclaration() &&
!isStaticCtorDeclaration()) { }

This makes the unittest work, but I don't know if that's a proper fix.

Any backend experts know more?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 13 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4669


Zhouxuan <pycerl qq.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pycerl qq.com



I came across this issue too, it really deserves more attentions,
how about the current status?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 05 2013