Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- import std.typetuple;
- enum ctfe;
- class AssertException : Exception
- {
- this (string message, string file = __FILE__, size_t line = __LINE__)
- {
- super(message, file, line);
- }
- }
- void myAssert (bool value, string file = __FILE__, size_t line = __LINE__)
- {
- if (!value)
- throw new AssertException("Assertion failed", file, line);
- }
- void bar (int a)
- {
- myAssert(a == 3);
- }
- @ctfe unittest
- {
- bar(4);
- }
- int runTest (alias test) ()
- {
- try
- test();
- catch (AssertException e)
- {
- assert(0); // should print some info here put writeln isn't ctfe-able
- return 1;
- }
- return 0;
- }
- template Tuple (T...)
- {
- alias Tuple = T;
- }
- int runCtfeUnitTests ()
- {
- int result;
- foreach (test ; __traits(getUnitTests, mixin(__MODULE__)))
- {
- alias attributes = Tuple!(__traits(getAttributes, test));
- if (staticIndexOf!(ctfe, attributes) != -1)
- result = runTest!(test);
- }
- return result;
- }
- enum result = runCtfeUnitTests();
- int main ()
- {
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement