[PATCH 5 of 5 c-hglib 🐮 ] README update with testing information

Giovanni Gherdovich g.gherdovich at gmail.com
Thu Nov 6 18:28:28 CST 2014


# HG changeset patch
# User Giovanni Gherdovich <g.gherdovich at gmail.com>
# Date 1412961476 -7200
#      Fri Oct 10 19:17:56 2014 +0200
# Node ID 7d733158583ab9ebc389e9d39e341e68757a8883
# Parent  97c608fdb4d69a143d2f52650b04f3aa0f0054ec
README update with testing information

List in the readme information about how to build
and run tests.

diff -r 97c608fdb4d6 -r 7d733158583a README
--- a/README	Sat Oct 11 09:49:44 2014 +0200
+++ b/README	Fri Oct 10 19:17:56 2014 +0200
@@ -259,6 +259,92 @@
   > rm .hg/store/data/foo.i
 
 
+Testing
+""""""""
+
+C-hglib includes the unit testing system "Greatest" originally writtent by Scott Vokes.
+
+* Available Assertions
+
++ `ASSERT(COND)`/`ASSERTm(MSG, COND)`
+
+    Assert that `COND` evaluates to a true value.
+
++ `ASSERT_FALSE(COND)`/`ASSERT_FAILm(MSG, COND)`
+
+    Assert that `COND` evaluates to a false value.
+
++ `ASSERT_EQ(EXPECTED, ACTUAL)`/`ASSERT_EQm(MSG, EXPECTED, ACTUAL)`
+
+    Assert that `EXPECTED == ACTUAL`. (To compare structures, use `ASSERT`
+    with your own function to compare the structures' members.)
+
++ `ASSERT_STR_EQ(EXPECTED, ACTUAL)`/`ASSERT_STR_EQm(MSG, EXPECTED, ACTUAL)`
+
+    Assert that `strcmp(EXPECTED, ACTUAL) == 0`.
+
+In all cases, the `m` version allows you to pass in a customized failure
+message. If an assertion without a custom message fails, `greatest` uses C
+preprocessor stringification to simply print the assertion's parameters.
+
+* Basic Usage
+
+```
+#include "greatest.h"
+
+TEST x_should_equal_1() {
+    int x = 1;
+    ASSERT_EQ(1, x);                              /* default message */
+    ASSERT_EQm("yikes, x doesn't equal 1", 1, x); /* custom message */
+    PASS();
+}
+
+SUITE(the_suite) {
+    RUN_TEST(x_should_equal_1);
+}
+
+/* Add definitions that need to be in the test runner's main file. */
+GREATEST_MAIN_DEFS();
+
+int main(int argc, char **argv) {
+    GREATEST_MAIN_BEGIN();      /* command-line arguments, initialization. */
+    RUN_SUITE(the_suite);
+    GREATEST_MAIN_END();        /* display results */
+}
+```
+
+To run the c-hglib unit tests:
+
+ > make tests
+ > LD_LIBRARY_PATH=/path/to/c-hglib:$LD_LIBRARY_PATH ./tests/test_runner
+ 
+ * Suite hg_level0_tests:
+ ..
+ 2 tests - 2 pass, 0 fail, 0 skipped (258 ticks, 0.000 sec) 
+ 
+ Total: 2 tests (386 ticks, 0.000 sec), 8 assertions
+ Pass: 2, fail: 0, skip: 0.
+
+Test cases should call assertions and then end in PASS(), SKIP(),
+FAIL(), or one of their message variants (e.g. `SKIPm("TODO");`).
+
+Tests and suites are just functions, so normal C scoping rules apply.
+
+(For more examples, look at example.c and example-suite.c.)
+
+* Command Line Options
+
+Test runners build with the following command line options:
+
+    Usage: (test_runner) [-hlfv] [-s SUITE] [-t TEST]
+      -h        print this Help
+      -l        List suites and their tests, then exit
+      -f        Stop runner after first failure
+      -v        Verbose output
+      -s SUITE  only run suite w/ name containing SUITE substring
+      -t TEST   only run test w/ name containing TEST substring
+
+
 Contact
 """"""""
 


More information about the Mercurial-devel mailing list