www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10992] New: Trait getUnitTests skips first test if aggregate contains multiple tests.

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

           Summary: Trait getUnitTests skips first test if aggregate
                    contains multiple tests.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: opantm2+dbugs gmail.com


--- Comment #0 from Kapps <opantm2+dbugs gmail.com> 2013-09-08 00:05:09 PDT ---
When using __traits(getUnitTests) on an aggregate that contains more than one
unittest, the first test will be skipped. If there is only one test, that
single test will be included.

Example:

import std.stdio;

unittest {
    writeln("Test 1");
}

unittest {
    writeln("Test 2");
}

unittest {
    writeln("Test 3");
}

void main() {
    writeln("main");
    foreach(t; __traits(getUnitTests, mixin(__MODULE__))) {
        t();
    }
}

Output (note that the tests should be run twice; once by default test runner):
Test 1
Test 2
Test 3
main
Test 2
Test 3

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


Jacob Carlborg <doob me.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |doob me.com


--- Comment #1 from Jacob Carlborg <doob me.com> 2013-09-08 12:54:04 PDT ---
I can't reproduce this in git HEAD.

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


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

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


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-09-08
12:57:10 PDT ---
I can with commit 25edff56d1c0e227bb16bf5369c7fee3be8cc630 on win32:

$ dmd -unittest -run test.d
 DMD v2.064 DEBUG
 Test 1
 Test 2
 Test 3
 main
 Test 2
 Test 3
-- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10992



--- Comment #3 from Jacob Carlborg <doob me.com> 2013-09-08 13:03:37 PDT ---
I still cannot reproduce it:

$ ./dmd -unittest -run main.d
Test 1
Test 2
Test 3
main
Test 1
Test 2
Test 3

Commit fc460eede168cf52879ca41191baf7db1f893569 on Mac OS X.

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



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-09-08
13:07:02 PDT ---
(In reply to comment #3)
 Commit fc460eede168cf52879ca41191baf7db1f893569 on Mac OS X.
(In reply to comment #3)
 I still cannot reproduce it:
 
 $ ./dmd -unittest -run main.d
 Test 1
 Test 2
 Test 3
 main
 Test 1
 Test 2
 Test 3
 
 Commit fc460eede168cf52879ca41191baf7db1f893569 on Mac OS X.
Hmm, maybe it's a platform-specific issue. I could look into it if you don't have a win32 system around. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10992



--- Comment #5 from Kapps <opantm2+dbugs gmail.com> 2013-09-08 13:14:40 PDT ---
(In reply to comment #4)
 
 Hmm, maybe it's a platform-specific issue. I could look into it if you don't
 have a win32 system around.
I'm running Linux 64-bit and generating 64-bit code. I don't have 32-bit libraries installed to test with unfortunately. archlptp:~$ dmd -m64 -unittest -run ptest.d Test 1 Test 2 Test 3 main Test 2 Test 3 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10992



--- Comment #6 from Jacob Carlborg <doob me.com> 2013-09-08 23:38:46 PDT ---
(In reply to comment #4)

 Hmm, maybe it's a platform-specific issue. 
Seems weird. I would think this would mostly be related to the front end.
 I could look into it if you don't have a win32 system around.
Please do. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10992



--- Comment #7 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-09-09
13:34:54 PDT ---
I've identified the problem:

UnitTestDeclaration *unitTest = symbol->unittest ? symbol->unittest :
symbol->isUnitTestDeclaration();
printf("-- %s %d\n", symbol->toChars(), unitTest);

This prints:

-- object 0
-- __unittestL3_1 2499632
-- __unittestL4_2 2500032
-- __unittestL5_3 2500032

Note how the last unittest has the same address as the one before it.

Here's a better printf:
printf("-- %s %d %d\n", symbol->toChars(), symbol->unittest,
symbol->isUnitTestDeclaration());

And the printout:

-- __unittestL3_1 2434096 2433696
-- __unittestL4_2 2434496 2434096
-- __unittestL5_3 0       2434496

Notice that the "unitTest" varriable assign statement will end up using the
address 2434496 twice.

 Jacob: The 'unittest' field was introduced by me, but I should have documented
it better. It should only be used for the DDOC documented unittest feature,
because what it really does is assigns the next physical unittest symbol to
whatever previous symbol there is (which itself might be a unittest).

So what should really be used is:

UnitTestDeclaration *unitTest = symbol->isUnitTestDeclaration();

I'll make a pull to fix this.

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
         AssignedTo|nobody puremagic.com        |andrej.mitrovich gmail.com


--- Comment #8 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-09-09
13:42:41 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2544

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



--- Comment #9 from Jacob Carlborg <doob me.com> 2013-09-10 00:31:18 PDT ---
(In reply to comment #7)

 So what should really be used is:
 
 UnitTestDeclaration *unitTest = symbol->isUnitTestDeclaration();
 
 I'll make a pull to fix this.
No, only "isUnitTestDeclaration" won't work. I've tried that. Sometimes "isUnitTestDeclaration" returns null but "unittest" contains something. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10992



--- Comment #10 from github-bugzilla puremagic.com 2013-09-30 03:44:45 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/331b5b0cb33433cbba391dd418ae36e8b454c4e6
Fixes Issue 10992 - Missing unittests when using getUnittests trait.

https://github.com/D-Programming-Language/dmd/commit/efe42756ade57a7cc029c7950293e65755b98aff
Merge pull request #2544 from AndrejMitrovic/Fix10992

Issue 10992 - Missing unittests when using getUnittests trait

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


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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