Thread overview
[Issue 4669] New: Unit tests do not work in libraries compiled by dmd with -lib
Aug 17, 2010
Mike Linford
Aug 17, 2010
Stephan Dilly
Aug 10, 2011
Mike Parker
Sep 15, 2011
Andrej Mitrovic
Oct 14, 2012
PhilLavoie
Jan 13, 2013
Andrej Mitrovic
Oct 06, 2013
Zhouxuan
August 17, 2010
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


--- Comment #0 from Mike Linford <mike.linford@gmail.com> 2010-08-17 08:55:13 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: -------
August 17, 2010
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


--- Comment #1 from Stephan Dilly <spam@extrawurst.org> 2010-08-17 10:13:09 PDT ---
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: -------
August 10, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4669


Mike Parker <aldacron@gmail.com> changed:

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


--- Comment #2 from Mike Parker <aldacron@gmail.com> 2011-08-10 03:49:56 PDT ---
*** 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: -------
September 15, 2011
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


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2011-09-15 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: -------
October 14, 2012
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


--- Comment #4 from PhilLavoie <maidenphil@hotmail.com> 2012-10-14 14:57:54 PDT ---
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: -------
January 13, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=4669



--- Comment #5 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-13 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: -------
October 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=4669


Zhouxuan <pycerl@qq.com> changed:

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


--- Comment #6 from Zhouxuan <pycerl@qq.com> 2013-10-05 22:15:19 PDT ---
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: -------