Skip to content

Commit

Permalink
Fixes wording of examples (#49)
Browse files Browse the repository at this point in the history
Co-authored-by: dcresswell <[email protected]>
  • Loading branch information
DerekCresswell and DerekCresswell authored May 6, 2020
1 parent 8585989 commit 06d39dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
22 changes: 10 additions & 12 deletions examples/c-example.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

#include "acutest.h"


void test_tutorial(void)
void
test_tutorial(void)
{
void* mem;

Expand All @@ -20,13 +20,13 @@ test_fail(void)
{
int a, b;

/* This condition is designed to fail so you can see how the failed test
/* This condition is designed to fail so you can see what the failed test
* output looks like. */
a = 1;
b = 2;
TEST_CHECK(a + b == 5);

/* Also show TEST_CHECK_ in action */
/* Here is TEST_CHECK_ in action. */
TEST_CHECK_(a + b == 5, "%d + %d == 5", a, b);

/* We may also show more information about the failure. */
Expand All @@ -35,15 +35,13 @@ test_fail(void)
TEST_MSG("b: %d", b);
}

/* The macros TEST_MSG() do write down something only when the precedin
* condition fails, so we can avoid the 'if'. */
/* The macro TEST_MSG() only outputs something when the preceding
* condition fails, so we can avoid the 'if' statement. */
TEST_CHECK(a + b == 3);
TEST_MSG("a: %d", a);
TEST_MSG("b: %d", b);
}



static void
helper(void)
{
Expand All @@ -59,7 +57,8 @@ test_abort(void)
{
helper();

/* This never happens because the test is aborted inside the helper(). */
/* This test never happens because the test is aborted inside the helper()
* function. */
TEST_CHECK(1 * 2 == 2 * 1);
}

Expand All @@ -69,11 +68,10 @@ test_crash(void)
int* invalid = ((int*)NULL) + 0xdeadbeef;

*invalid = 42;
TEST_CHECK_(1 == 1, "We should never get here, due to the write into "
"the invalid address.");
TEST_CHECK_(1 == 1, "This should never execute, due to a write into "
"an invalid address.");
}


TEST_LIST = {
{ "tutorial", test_tutorial },
{ "fail", test_fail },
Expand Down
10 changes: 4 additions & 6 deletions examples/cpp-example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ enum What {
};

/* This dummy function represents some code which we want to test.
* As we are in C++, they can throw some exceptions.
* As this is written in C++, they can throw exceptions.
*/
static void
some_function(What what, const char* msg = NULL)
Expand Down Expand Up @@ -72,12 +72,12 @@ void test_exception_type(void)
TEST_EXCEPTION(some_function(THROW_TEST_EXC), std::exception);
TEST_EXCEPTION(some_function(THROW_INVALID_ARG), std::exception);

/* Uncommon types used as exceptions work too. */
/* Fundemental types used as exceptions work too. */
TEST_EXCEPTION(some_function(THROW_CHAR_PTR), const char*);
TEST_EXCEPTION(some_function(THROW_INT), int);

/* These checks fail because the given code does not throw an exception
* at all, or throws something incompatible. */
* at all, or throws a different type of exception. */
TEST_EXCEPTION(some_function(NO_THROW), std::exception);
TEST_EXCEPTION(some_function(THROW_INT), std::exception);
TEST_EXCEPTION(some_function(THROW_INVALID_ARG), TestException);
Expand All @@ -96,9 +96,7 @@ void test_uncaught_std_exception(void)
void test_uncaught_strange_exception(void)
{
/* If the test throws unhandled exception, Acutest aborts the test unit
* and considers it a failure.
*
* Even if it is not derived from std::exception.
* and considers it a failure even if it is not derived from std::exception.
*/
some_function(THROW_CHAR_PTR, "Acutest knows how to catch me :-)");
}
Expand Down

0 comments on commit 06d39dd

Please sign in to comment.