diff options
author | katherine <shmibs@shmibbles.me> | 2018-03-21 01:26:51 -0700 |
---|---|---|
committer | katherine <shmibs@shmibbles.me> | 2018-03-21 01:26:51 -0700 |
commit | 00b9a76f9583ef8be6952f921ecd89cc5492375e (patch) | |
tree | a70a9ba548126198af187eb5ffe592308149e4e4 | |
parent | d64ce0ad863bd26a690120808554ab9080d1ec04 (diff) | |
download | simple-test-00b9a76f9583ef8be6952f921ecd89cc5492375e.tar.gz |
proofread
-rw-r--r-- | README.md | 50 | ||||
-rw-r--r-- | doc/example.c | 4 |
2 files changed, 31 insertions, 23 deletions
@@ -3,7 +3,7 @@ simple-test [simple-test.h](simple-test.h) is a single header file which implements quick-and-dirty unit testing for C. robust unit testing suites for C exist, but -require a degree of boilerplate which can be prohibitive for their use in +they require a degree of boilerplate which can be prohibitive for their use in spare-time projects. if you're writing something for fun, lots of boilerplate defeats the purpose of writing it. simple-test is made to be as easy to use as possible: include the header, compile, and run. @@ -20,7 +20,7 @@ functionality to be tested. include the functionality needed (including headers and linking against objects) to produce an executable file from the .c file, then run the executable to test. simple-test internally defines a `main` function, so none is required, and the `argc` and `argv` arguments are made -available to all `TEST`s. +available to all tests. example @@ -39,7 +39,7 @@ char *global_s; * occurs either after an ASSERT fails or after the TEST is finished. * * defining one is optional, but, if used, REGISTER_TEARDOWN must appear - * between BEGIN_TEST and the first TEST + * between BEGIN_TEST and the first TEST statement. * * here i'm using it to free memory that's alloced inside tests below */ void teardown(void) @@ -81,7 +81,7 @@ TEST("type mismatch") int i = 97; char *b = NULL; - /* for convenience's sake, when presented with unmatched types, assertions + /* for convenience's sake, when presented with mismatched types, assertions * try to resolve them in a way that's most likely to match the * programmer's intentions. here 'i' is interpreted as a char */ ASSERT_EQ(a, i); @@ -139,11 +139,11 @@ on compiling and running this file, the output will look something like this: ![run 1](doc/run_01.png) -an error, because the types passed to the second assertion in the "type -mismatch" test are... well, mismatched. simple-test does its best to -accommodate mismatched types when it makes sense to do so (e.g. comparing a -signed and unsigned integer), but there is no meaningful comparison to be made -between a `char` and a `char *`, so the error is returned. +an error occurs because the types passed to the second assertion in the "type +mismatch" test are... well, mismatched. assertions do their best to accommodate +mismatched types when it makes sense to do so (e.g. comparing a signed and +unsigned integer), but there is no meaningful comparison to be made between a +`char` and a `char *`, so the error is returned. if that assertion is commented out: @@ -157,7 +157,7 @@ and the tests re-run, the output would look like this: ![run 2](doc/run_02.png) -as you can see, there are multiple failing assertions, and their failures are +as you can see, there are multiple failing assertions. their failures are reported and a total count of failing tests printed. if all of these failing asserts are commented out and the tests re-run, the output looks like this: @@ -181,14 +181,22 @@ simple-test's interface consists of a series of preprocessor macros: | **ECHO(<...>)** | print a formatted description of the state within the current test | | **ASSERT<_condition>(<args>)** | assert, on either one or two `args`, that `_condition` is true | -valid values for `_condition` are: - -| **_condition** | **DESCRIPTION** | -|---------------:|:----------------| -| | if the _condition is omitted, fail if the single argument is a "not" value, i.e. NULL, 0, '\0' etc. | -| **_EQ** | fail if the two arguments are not equal | -| **_NEQ** | fail if the two arguments are equal | -| **_GT** | fail if the first argument is not greater than the second | -| **_GEQ** | fail if the first argument is not greater than or equal to the second | -| **_LT** | fail if the first argument is not less than the second | -| **_LEQ** | fail if the first argument is not less than or equal to the second | +valid assertions are: + +| **NAME** | **DESCRIPTION** | +|---------:|:----------------| +| **ASSERT(<a>)** | assert that the value of `a` is not a "not" value, i.e. NULL, 0, or '\0' | +| **ASSERT_NOT(<a>)** | assert that the value of `a` is a "not" value | +| **ASSERT_EQ(<a>, <b>)** | fail if the values of `a` and `b` are not equal | +| **ASSERT_NEQ(<a>, <b>)** | fail if the values of `a` and `b` are equal | +| **ASSERT_GT(<a>, <b>)** | fail if the value of `a` is not greater the value of `b` | +| **ASSERT_GEQ(<a>, <b>)** | fail if the value of `a` is not greater than or equal to the value of `b` | +| **ASSERT_LT(<a>, <b>)** | fail if the value of `a` is not less than the value of `b` | +| **ASSERT_LEQ(<a>, <b>)** | fail if the value of `a` is not less than or equal to the value of `b` | + + +note +---- + +simple-test.h internally uses macros prefixed with `SIMPLE_TEST_` and functions +and variables prefixed with `simple_test_`. these should not be used directly. diff --git a/doc/example.c b/doc/example.c index 26d8f66..6341a1f 100644 --- a/doc/example.c +++ b/doc/example.c @@ -7,7 +7,7 @@ char *global_s; * occurs either after an ASSERT fails or after the TEST is finished. * * defining one is optional, but, if used, REGISTER_TEARDOWN must appear - * between BEGIN_TEST and the first TEST + * between BEGIN_TEST and the first TEST statement. * * here i'm using it to free memory that's alloced inside tests below */ void teardown(void) @@ -49,7 +49,7 @@ TEST("type mismatch") int i = 97; char *b = NULL; - /* for convenience's sake, when presented with unmatched types, assertions + /* for convenience's sake, when presented with mismatched types, assertions * try to resolve them in a way that's most likely to match the * programmer's intentions. here 'i' is interpreted as a char */ ASSERT_EQ(a, i); |