Skip to content

Commit

Permalink
Documentation/example changes for new assetions
Browse files Browse the repository at this point in the history
This tracks recent changes for new assertions, as well as the
addition of date information in XML files.
  • Loading branch information
whart222 committed May 5, 2013
1 parent fcfa5f1 commit 3f3212c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
38 changes: 38 additions & 0 deletions doc/examples/Assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ class Test : public CxxTest::TestSuite
}
// @:assertEquals

// @assertIsNan:
void test_assert_is_nan(void)
{
TS_ASSERT_IS_NAN( 0.0/0.0 );
}
// @:assertIsNan

// @assertIsInfinite:
void test_assert_is_infinite(void)
{
TS_ASSERT_IS_INFINITE( 1.0/0.0 );
}
// @:assertIsInfinite

// @assertLessThan:
void test_assert_less_than(void)
{
Expand Down Expand Up @@ -115,6 +129,30 @@ class Test : public CxxTest::TestSuite
}
// @:assertThrowsEquals

// @assertThrowsIsNan:
void throws_nan(void)
{
raise 0.0/0.0;
}

void test_assert_throws_is_nan(void)
{
TS_ASSERT_THROWS_IS_NAN(self.throws_nan(), const Error & e, e.what());
}
// @:assertThrowsIsNan

// @assertThrowsIsInfinite:
void throws_infinite(void)
{
raise 1.0/0.0;
}

void test_assert_throws_is_infinite(void)
{
TS_ASSERT_THROWS_IS_INFINITE(self.throws_infinite(), const Error & e, e.what());
}
// @:assertThrowsIsInfinite

// @assertThrowsNothing:
void throws_nothing(void)
{ }
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/buildRunner6.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite name="cxxtest" tests="2" errors="0" failures="1" time="0" >
<testsuite name="cxxtest" date="Tue Apr 23 23:28:43 2013" tests="2" errors="0" failures="1" time="0" >
<testcase classname="MyTestSuite2" name="testAddition" line="7" />
<testcase classname="MyTestSuite2" name="testMultiplication" line="13">
<failure file="MyTestSuite2.h" line="16" type="failedAssertEquals" >Error: Expected (2 * 2 == 5), found (4 != 5)</failure>
Expand Down
11 changes: 11 additions & 0 deletions doc/examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,21 @@

compilerre = re.compile("^(?P<path>[^:]+)(?P<rest>:.*)$")
dirre = re.compile("^([^%s]*/)*" % re.escape(os.sep))
xmlre = re.compile("\"(?P<path>[^\"]*/[^\"]*)\"")
datere = re.compile("date=\"[^\"]*\"")
failure = re.compile("^(?P<prefix>.+)file=\"(?P<path>[^\"]+)\"(?P<suffix>.*)$")

#print "FOO", dirre
def filter(line):
# for xml, remove prefixes from everything that looks like a
# file path inside ""
line = xmlre.sub(
lambda match: '"'+re.sub("^[^/]+/", "", match.group(1))+'"',
line
)
# Remove date info
line = datere.sub( lambda match: 'date=""', line)

if 'Running' in line:
return False
if "IGNORE" in line:
Expand Down
34 changes: 33 additions & 1 deletion doc/guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,12 @@ The following table summarizes the test assertions supported by CxxTest.
[options="header"]
|====================================================================================
| Macro | Description
| <<ts_assert,+TS_ASSERT(expr)+>> | Verify +expr+ is true
| <<ts_assert,+TS_ASSERT(expr)+>> | Verify +expr+ is true
| xref:ts_assert_delta[+TS_ASSERT_DELTA(x,y,d)+] | Verify that +abs(x-y) < d+
| xref:ts_assert_differs[+TS_ASSERT_DIFFERS(x,y)+] | Verify that +x != y+
| xref:ts_assert_equals[+TS_ASSERT_EQUALS(x,y)+] | Verify that +x == y+
| <<ts_assert_is_nan,+TS_ASSERT_IS_NAN(x)+>> | Verify that +x+ is NaN
| <<ts_assert_is_infinite,+TS_ASSERT_IS_INFINITE(x)+>> | Verify that +x+ is infinite
| xref:ts_assert_less_than[+TS_ASSERT_LESS_THAN(x,y)+] | Verify that +x < y+
| xref:ts_assert_less_than_equals[+TS_ASSERT_LESS_THAN_EQUALS(x,y)+] | Verify that +x <= y+
| xref:ts_assert_predicate[+TS_ASSERT_PREDICATE(P,x)+] | Verify +P(x)+
Expand All @@ -222,6 +224,8 @@ The following table summarizes the test assertions supported by CxxTest.
| <<ts_assert_throws_anything,+TS_ASSERT_THROWS_ANYTHING(expr)+>> | Verify that +expr+ throws an exception
| xref:ts_assert_throws_assert[+TS_ASSERT_THROWS_ASSERT(expr,arg,assertion)+] | Verify type and value of what +expr+ throws
| xref:ts_assert_throws_equals[+TS_ASSERT_THROWS_EQUALS(expr,arg,x,y)+] | Verify type and value of what +expr+ throws
| xref:ts_assert_throws_is_nan[+TS_ASSERT_THROWS_IS_NAN(expr,arg,x)+] | Verify type and value of what +expr+ throws
| xref:ts_assert_throws_is_infinite[+TS_ASSERT_THROWS_IS_INFINITE(expr,arg,x)+] | Verify type and value of what +expr+ throws
| <<ts_assert_throws_nothing,+TS_ASSERT_THROWS_NOTHING(expr)+>> | Verify that +expr+ doesn't throw anything
| <<ts_fail,+TS_FAIL(message)+>> | Fail unconditionally
| <<ts_skip,+TS_SKIP(message)+>> | Skip this test
Expand Down Expand Up @@ -1344,6 +1348,20 @@ include::examples/.Assertions_assertEquals.h[]
----
Note that this test is performed using the C++ +==+ operator, whose behavior may be redefined for the two argument types.
[[ts_assert_is_nan]] TS_ASSERT_IS_NAN::
This test assertion verifies that the argument is NaN:
[source,{cpp}]
----
include::examples/.Assertions_assertIsNan.h[]
----
[[ts_assert_is_infinite]] TS_ASSERT_IS_INFINITE::
This test assertion verifies that the argument is infinite:
[source,{cpp}]
----
include::examples/.Assertions_assertIsInfinite.h[]
----
[[ts_assert_less_than]] TS_ASSERT_LESS_THAN::
This test assertion verifies that the first argument is strictly less than the second argument:
[source,{cpp}]
Expand Down Expand Up @@ -1415,6 +1433,20 @@ This test assertion verifies that an exception is thrown when executing the firs
include::examples/.Assertions_assertThrowsEquals.h[]
----
[[ts_assert_throws_is_nan]] TS_ASSERT_THROWS_IS_NAN::
This test assertion verifies that an exception is thrown when executing the first argument. The second argument specifies a variable declaration for the exception, and the third argument is a value that are asserted to be NaN after the exception is thrown:
[source,{cpp}]
----
include::examples/.Assertions_assertThrowsIsNan.h[]
----
[[ts_assert_throws_is_infinite]] TS_ASSERT_THROWS_IS_INFINITE::
This test assertion verifies that an exception is thrown when executing the first argument. The second argument specifies a variable declaration for the exception, and the third argument is a value that are asserted to be infinite after the exception is thrown:
[source,{cpp}]
----
include::examples/.Assertions_assertThrowsIsInfinite.h[]
----
[[ts_assert_throws_nothing]] TS_ASSERT_THROWS_NOTHING::
This test assertion verifies that an exception is _not_ thrown when executing the first argument:
[source,{cpp}]
Expand Down

0 comments on commit 3f3212c

Please sign in to comment.