digitalmars.D.learn - unittests not being run
- Bahman Movaqar (23/23) Jul 15 2016 The test I have in 'app.d' don't get picked up by 'dub test' in a
- Jerry (2/2) Jul 15 2016 Unittests have to be inside a module to be run on DMD atleast.
- Bahman Movaqar (26/28) Jul 15 2016 Strange. Still not getting picked up.
- Seb (6/33) Jul 16 2016 There is no need for a module, but dub by default only checks
- Bahman Movaqar (7/12) Jul 16 2016 Indeed, that's a slimmed down version of my code. Though the real code
The test I have in 'app.d' don't get picked up by 'dub test' in a freshly created project by 'dub init'. $ dub test Generating test runner configuration '__test__library__' for 'library' (library). Performing "unittest" build using dmd for x86_64. dplay ~master: building configuration "__test__library__"... Linking... Running ./__test__library__ All unit tests have been run successfully. [app.d] import std.stdio; private int incBy1(int i) { return i + 1; } unittest { assert(foo(1) == 200); } void main() { writeln("hi"); } What am I missing? Thanks in advance, -- Bahman
Jul 15 2016
Unittests have to be inside a module to be run on DMD atleast. So putting module foo at top should fix it.
Jul 15 2016
On 07/15/2016 04:16 PM, Jerry wrote:Unittests have to be inside a module to be run on DMD atleast. So putting module foo at top should fix it.Strange. Still not getting picked up. $ dmd --version DMD64 D Compiler v2.071.0 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright [app.d] module app; import std.stdio; private int incBy1(int i) { return i + 1; } unittest { assert(incBy1(1) == 200); } void main() { writeln(incBy1(1)); // which prints 2 } [/app.d] $ dub test Generating test runner configuration '__test__library__' for 'library' (library). Performing "unittest" build using dmd for x86_64. dplay ~master: building configuration "__test__library__"... Linking... Running ./__test__library__ All unit tests have been run successfully. -- Bahman
Jul 15 2016
On Friday, 15 July 2016 at 11:59:51 UTC, Bahman Movaqar wrote:On 07/15/2016 04:16 PM, Jerry wrote:There is no need for a module, but dub by default only checks files in the 'source' folder. For such simple tests you could also run them directly with rdmd -unittest. There is an additional -main flag if you don't need a main method.Unittests have to be inside a module to be run on DMD atleast. So putting module foo at top should fix it.Strange. Still not getting picked up. $ dmd --version DMD64 D Compiler v2.071.0 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright [app.d] module app; import std.stdio; private int incBy1(int i) { return i + 1; } unittest { assert(incBy1(1) == 200); } void main() { writeln(incBy1(1)); // which prints 2 } [/app.d] $ dub test Generating test runner configuration '__test__library__' for 'library' (library). Performing "unittest" build using dmd for x86_64. dplay ~master: building configuration "__test__library__"... Linking... Running ./__test__library__ All unit tests have been run successfully.
Jul 16 2016
On 07/17/2016 12:38 AM, Seb wrote:There is no need for a module, but dub by default only checks files in the 'source' folder.The file is already in the 'source' folder.For such simple tests you could also run them directly with rdmd -unittest. There is an additional -main flag if you don't need a main method.Indeed, that's a slimmed down version of my code. Though the real code is different (not this simple and already has a `main`) the problem is the same. -- Bahman
Jul 16 2016