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

Commit

Permalink
Generalize assert_fail:test to accept any expression
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonlightSentinel committed Nov 2, 2019
1 parent 24bdab0 commit caf2ce5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test/exceptions/src/assert_fail.d
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import core.stdc.stdio : fprintf, printf, stderr;

void test(string comp = "==", A, B)(A a, B b, string msg, size_t line = __LINE__)
{
test(assert(mixin("a " ~ comp ~ " b")), msg, line);
}

void test(T)(lazy T dg, string msg, size_t line = __LINE__)
{
int ret = () {
import core.exception : AssertError;
try
{
assert(mixin("a " ~ comp ~ " b"));
dg();
} catch(AssertError e)
{
// don't use assert here for better debugging
Expand Down Expand Up @@ -111,13 +116,13 @@ void testStruct()()
test(T([T(null)]), T(null), "[T([])] != []");

https://issues.dlang.org/show_bug.cgi?id=20323
struct NoCopy
static struct NoCopy
{
@disable this(this);
}

NoCopy n;
assert(n == n);
test(assert(n != n), "NoCopy() is NoCopy()");
}

void testAA()()
Expand Down Expand Up @@ -155,7 +160,7 @@ void testTemporary()
~this() @system {}
}

assert(Bad() == Bad());
test(assert(Bad() != Bad()), "Bad() is Bad()");
}

void main()
Expand Down

1 comment on commit caf2ce5

@PetarKirov
Copy link
Member

Choose a reason for hiding this comment

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

Nicely done!

Please sign in to comment.