Skip to content

Commit

Permalink
support for unit-threaded's fluent assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
linkrope committed Aug 31, 2016
1 parent 89741aa commit 8acf65b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ So, if you prefer TestNG's order of arguments,
import `dunit.ng` or `dunit.ng.assertion`
instead of the conventional `dunit` and `dunit.assertion`.

Fluent Assertions
-----------------

The xUnit Testing Framework also supports the "fluent assertions" from
[unit-threaded](https://github.com/atilaneves/unit-threaded).

For an example, have a look at [fluent-assertions](fluent_assertions.d).
Build and run the example using

dub --config=fluent-assertions

(When you get three failures, everything works fine.)

Related Projects
----------------

Expand Down
10 changes: 9 additions & 1 deletion dub.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "d-unit",
"description": "xUnit Testing Framework for D",
"copyright": "Copyright © 2013, Mario Kröplin",
"copyright": "Copyright © 2016, Mario Kröplin",
"authors": ["Juan Manuel Cabo", "Mario Kröplin"],
"license" : "BSL-1.0",
"dependencies": {},
Expand All @@ -15,6 +15,14 @@
"name": "example",
"targetType": "executable",
"sourceFiles": ["example.d"]
},
{
"name": "fluent-assertions",
"targetType": "executable",
"sourceFiles": ["fluent_assertions.d"],
"dependencies": {
"unit-threaded": ">=0.6.27"
}
}
]
}
2 changes: 1 addition & 1 deletion example.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env dub
/+ dub.sdl:
name "example"
dependency "d-unit" version=">=0.7.2"
dependency "d-unit" version=">=0.8.0"
+/

// Copyright Juan Manuel Cabo 2012.
Expand Down
35 changes: 35 additions & 0 deletions fluent_assertions.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright Mario Kröplin 2016.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

module fluent_assertion;

import dunit;
import unit_threaded.should : shouldBeIn, shouldEqual, shouldNotEqual;

class Test
{
mixin UnitTest;

@Test
public void shouldEqualFailure()
{
"bar".shouldEqual("baz");
}

@Test
public void shouldNotEqualFailure()
{
"foo".shouldNotEqual("foo");
}

@Test
public void shouldBeInFailure()
{
42.shouldBeIn([0, 1, 2]);
}
}

// either use the 'Main' mixin or call 'dunit_main(args)'
mixin Main;
20 changes: 19 additions & 1 deletion src/dunit/framework.d
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,25 @@ body
{
try
{
action();
static if (__traits(compiles, { import unit_threaded.should : UnitTestException; }))
{
import unit_threaded.should : UnitTestException;

try
{
action();
}
catch (UnitTestException exception)
{
// convert exception to "fix" the message format
throw new AssertException('\n' ~ exception.msg,
exception.file, exception.line, exception);
}
}
else
{
action();
}
return true;
}
catch (AssertException exception)
Expand Down

0 comments on commit 8acf65b

Please sign in to comment.