Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Conversation

jpf91
Copy link
Contributor

@jpf91 jpf91 commented May 1, 2014

See dlang/dmd#3518 for much more details.

Default druntime tester

Updated to ignore @disabled tests and use the new format.
The tester now runs all tests in a module, even if a previous test failed.

Example test runner

Simple example: http://dpaste.dzfl.pl/56697348500c
Output: http://dpaste.dzfl.pl/c0c706b0cea4

Parallel runner: http://dpaste.dzfl.pl/cef0a42936d6
Output: http://dpaste.dzfl.pl/d2445d87a9d7

See also

DMD pull request:
dlang/dmd#3518

@jpf91 jpf91 changed the title Enhance unittest support Enhanced unittest support May 2, 2014
@jacob-carlborg
Copy link
Contributor

What's the versioning, _V1 and ver?

@jacob-carlborg
Copy link
Contributor

One useful change would be calling every single test in a try block, not the complete module. This way testing would continue after a test failed in the module. Thoughts?

Yes please.

@jpf91
Copy link
Contributor Author

jpf91 commented May 2, 2014

@jacob-carlborg you mean what that versioning is for? It's not necessary right now, but it allows changing the exported fields in the future without modifying the moduleinfo flags and we can stay 100% ABI compatible.

For example if we want to add a new field later on, e.g. name, then we define a new __UnitTest_V2 struct with that field added. But we could also remove fields from __UnitTest_V2, it can be completely different from __UnitTest_V1. Then an old druntime, which only supports __UnitTest_V1 will simply ignore(*) __UnitTest_V2 tests generated by a newer compiler. And a newer runtime can still run tests compiled by an older compiler.

(*) We could define a common set of functionality shared by all versions, __UnitTest_V0. This could include the function pointer. A old runtime could then also run all new tests generated by a newer compiler. But there's a drawback: If we add stuff like disabled to the new __UnitTest_Vx struct a old runtime couldn't detect this with __UnitTest_V0 and would always run these tests.

@jacob-carlborg
Copy link
Contributor

Ok, I see.

/**
* Deprecated:
* Please use unitTests instead.
*/
@property void function() unitTest() nothrow pure
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This thing was particularly nasty, a property function returning a function (especially when we have things like -property being in murky waters).

@WalterBright
Copy link
Member

I think an additional versioning scheme is redundant. We can already add bits to the flags, as this does already.

@@ -1597,6 +1597,7 @@ enum
MIimportedModules = 0x400,
MIlocalClasses = 0x800,
MIname = 0x1000,
MInewUnitTest = 0x2000,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use MIunitTest2 instead. Using new is not workable when the next one is needed, after all, would that be called evenNewer ? :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change it, but we hopefully never need a MIunitTest3. MIunitTest2 only enforces representing tests in a module as an 'array of something' where 'something' can be any struct. So MIunitTest2 should be future proof for some time.

@joakim-noah
Copy link
Contributor

Can we please get this in? I've been running the phobos unit tests a lot lately and it's very annoying for all the rest of the tests not to run if a single assert fails somewhere in the middle.

@property void function() unitTest() nothrow pure
{
return flags & MIunitTest ? *cast(typeof(return)*)addrOf(MIunitTest) : null;
}

@property __UnitTest[] unitTests() nothrow
{
return flags & MIunitTest2 ? *cast(typeof(return)*)addrOf(MIunitTest2) : [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning null instead of [] saves you a call to _d_arrayliteral.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this had also been fixed in dmd but it seems you're right. (Iain fixed it in gdc some time ago)

jpf91 added 3 commits May 20, 2014 18:59
The new information is available from the 'unitTests' member of
every ModuleInfo.
'unitTests' is an array of __UnitTest structs. The __UnitTest
struct provides the unittest function, location etc.
@MartinNowak
Copy link
Member

Auto-merge toggled on

MartinNowak added a commit that referenced this pull request May 23, 2014
@MartinNowak MartinNowak merged commit f63d1d7 into dlang:master May 23, 2014
@@ -18,25 +18,35 @@ bool tester()
if(name.length > pkgLen && name[$ - pkgLen .. $] == pkg)
name = name[0 .. $ - pkgLen];

if (auto fp = getModuleInfo(name).unitTest)
bool result = true;
if (auto tests = getModuleInfo(name).unitTests)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aww, there is no fallback in the test runner. This actually disabled all tests on our auto-tester.
See #808 for a fixup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that. I added the fallback in src/core/runtime.d but it seems I forgot to add it in the druntime/phobos test runner. Thanks for merging, btw. I'll update the dmd pull later today.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants