summaryrefslogtreecommitdiff
path: root/libs/greatest
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-09-14 15:27:51 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-09-14 15:27:51 +0200
commit76d3082e5b89fe54acaaaaadd201ccc92f4f346e (patch)
tree32d5212d87bc0b4cab06bcbe923f7eeb019268b0 /libs/greatest
parent38019a9693375ac6719ffec43bff63774e142387 (diff)
tests for administration io
Diffstat (limited to 'libs/greatest')
-rw-r--r--libs/greatest/.gitignore8
-rw-r--r--libs/greatest/CHANGELOG.md544
-rw-r--r--libs/greatest/CONTRIBUTING.md73
-rw-r--r--libs/greatest/LICENSE13
-rw-r--r--libs/greatest/Makefile52
-rw-r--r--libs/greatest/README.md475
-rw-r--r--libs/greatest/contrib/entapment107
-rw-r--r--libs/greatest/contrib/greenest33
-rw-r--r--libs/greatest/contrib/testify33
-rw-r--r--libs/greatest/greatest.h1266
-rw-r--r--libs/greatest/package.json9
11 files changed, 2613 insertions, 0 deletions
diff --git a/libs/greatest/.gitignore b/libs/greatest/.gitignore
new file mode 100644
index 0000000..159eeef
--- /dev/null
+++ b/libs/greatest/.gitignore
@@ -0,0 +1,8 @@
+example
+example_no_suite
+example_no_runner
+example_random
+example_shuffle
+example_trunc
+example_cpp
+*.o
diff --git a/libs/greatest/CHANGELOG.md b/libs/greatest/CHANGELOG.md
new file mode 100644
index 0000000..47f37ec
--- /dev/null
+++ b/libs/greatest/CHANGELOG.md
@@ -0,0 +1,544 @@
+# greatest Changes By Release
+
+## v1.5.0 - 2021-02-15
+
+### API Changes
+
+Changed default: `GREATEST_USE_LONGJMP` now defaults to 0. This eliminates
+a warning about variables that can possibly become stale/corrupt in the
+presence of `longjmp`. Since `GREATEST_FAIL_WITH_LONGJMP` isn't frequently
+used, it should probably be opt-in.
+
+Added `greatest_set_exact_name_match()` / `-e` flag, which changes the
+name-based filtering from substring to exact match. Note that filtering
+on an exact suite name will not skip tests run outside of any suite.
+
+Added `GREATEST_ASSERT_NEQ` and `GREATEST_ASSERT_NEQm`. (Thanks @tekknolagi.)
+
+Added `GREATEST_ASSERT_GT`, `GREATEST_ASSERT_GTE`, `GREATEST_ASSERT_LT`,
+and `GREATEST_ASSERT_LTE`, along with their custom message (`m`)
+variants.
+
+
+### Bug Fixes
+
+Makefile: Fix targets so all files are rebuilt when `greatest.h` or the
+`Makefile` are modified, but without potentially breaking the build due
+to including `greatest.h` as a linker argument to `example_trunc` (which
+could happen with clang). (Thanks @vemakereporter, @theosotr.)
+
+Calls to `GREATEST_RUN_TEST` from inside another test are now ignored.
+
+Other flags starting with `--` besides `--help` (print help) and `--`
+(ignore rest of ARGV) now produce an "Unknown argument" message;
+previously they were unintentionally handled like `--`.
+
+
+### Other Improvements
+
+Added built `example_cpp` executable to `.gitignore`.
+
+Expanded on the role of `RUN_TEST`, `RUN_TEST1`, `RUN_TESTp`,
+`PASS`, `SKIP`, and `FAIL` in the README.
+
+Addressed a `-Wimplicit-fallthrough` warning when building with clang
+using `-Weverything`.
+
+
+## v1.4.2 - 2019-03-24
+
+### API Changes
+
+None.
+
+
+### Other Improvements
+
+Fixed configuration parameters for the PRNG (used for shuffling).
+Previously, certain rare combinations of test counts and input states
+could prevent the linear congruential RNG from having its full period
+before repeating values, which could cause tests to be run multiple
+times or skipped during shuffling.
+
+Fixed an assertion in the example code where the expected annd actual
+parameters were swapped. (Reported by @shaohuasong.)
+
+Updated a comment to reflect that `GREATEST_ASSERT_STR_EQm` compares
+using `strncmp`, not `strcmp`. (Reported by @orangewait.)
+
+Minor formatting improvements in the README.
+
+
+## v1.4.1 - 2018-12-30
+
+### API Changes
+
+None.
+
+
+### Other Improvements
+
+Fixed a warning when compiled with `-Wconversion`. (Thanks @HawkSK.)
+
+Replaced a remaining direct use of `fprintf` with `GREATEST_FPRINTF`.
+(Thanks @ligurio.)
+
+Fixed typo in example code. (Thanks @ligurio.)
+
+Bugfix: Previously, a test failure in first-fail mode didn't prevent
+later suites from running.
+
+Added a comment noting that the duplicated declaration inside the
+`GREATEST_SUITE` macro is intentional.
+
+Renamed `exp` local variable to `expd`, to prevent a possible
+warning about shadowing `exp(3)`.
+
+Updated the command line argument documentation in the README and
+the usage message.
+
+Added a description of output behaviors for each test case
+result type, and clarified that the custom message variants
+(e.g. `SKIPm("TODO")`) can be used to set custom messages, but
+do not affect whether or not the message is printed.
+
+
+## v1.4.0 - 2018-03-05
+
+### API Changes
+
+Added `greatest_abort_on_fail`, which sets a flag to call `abort()` on
+the first test failure (`-a` in the CLI test runner). If tests are
+running inside a debugger, this will break right on the failure.
+Feature suggestion and initial implementation by @fsaintjacques.
+
+Added `greatest_list_only()`, which sets the same flag as the `-l`
+option in the CLI test runner.
+
+Added `greatest_set_test_suffix(const char *suffix)`, which can
+be used to add a suffix to the name printed for the next test.
+This can be used to distinguish between tests when running
+parametric tests (particularly when shuffled). Note that this
+suffix is included in the matching for `-t` and `-x`.
+
+The `greatest_info` struct now allocates a `char` buffer for the test
+name and optional '_' separator & suffix. The buffer size can be
+configured by `#define`ing `GREATEST_TESTNAME_BUF_SIZE`. (See
+`example_trunc.c`.) If the test name plus optional suffix does not fit
+in the buffer, it will be truncated and `\0` terminated.
+
+Made a couple functions `static` that were previously exposed, but
+explictly listed as being internal (`greatest_do_pass`,
+`greatest_do_fail`, `greatest_do_skip`, `greatest_suite_pre`,
+`greatest_suite_post`, `greatest_usage`).
+
+
+### Other Improvements
+
+Fixed link to ISC license in README.md. (Thanks @vaibhavsagar.)
+
+Fixed issue link and whitespace in README.md and CONTRIBUTING.md.
+(Thanks @bebehei.)
+
+Change a couple macros into functions: `GREATEST_INIT` and
+`GREATEST_PRINT_REPORT`. Most of the macros have variable capture,
+return from their call site, etc., but these two don't need to be
+macros.
+
+
+## v1.3.1 - 2017-09-22
+
+### API Changes
+
+None.
+
+
+### Other Improvements
+
+Bugfix: `GREATEST_SHUFFLE_TESTS` and `GREATEST_SHUFFLE_SUITES`
+did not check for the `stop_at_first_fail` flag, and could get
+stuck in an infinite loop. Now their loops stop as expected.
+
+Renamed `example_random.c` to `example_shuffle.c`, since its
+focus is really on random shuffling of suites and tests.
+
+
+## v1.3.0 - 2017-08-13
+
+### API Changes
+
+Added `GREATEST_SHUFFLE_SUITES(SEED, BODY)` macro (and `SHUFFLE_SUITES`
+abbreviation). This runs any suites within BODY in pseudorandom order,
+seeded by SEED.
+
+Added `GREATEST_SHUFFLE_TESTS(SEED, BODY)` macro (and `SHUFFLE_TESTS`
+abbreviation). This runs any tests within BODY in pseudorandom order,
+seeded by SEED.
+
+If `GREATEST_NO_EXTERN_CPLUSPLUS` is `#define`d, then the C++
+`extern "C" { ... }` namespacing around greatest is disabled.
+
+All calls to `fprintf` have been wrapped in a macro, `GREATEST_FPRINTF`,
+which can be `#define`d to substitute another function with the same
+interface. Feature suggestion and initial implementation by
+@AndreasMartin72.
+
+Added `greatest_stop_at_first_fail()`, to set the flag to stop the test
+runner at the first failure (`-f` in the CLI test runner).
+
+Added `void greatest_test_exclude(const char *filter)`, which takes a
+filter string and ignores all tests whose names contain the filter
+string. This takes precedence over `greatest_test_filter` matches.
+
+Added a CLI test runner option, `-x`, which calls
+`greatest_test_exclude` with its argument.
+
+
+### Other Improvements
+
+Bugfix: `GREATEST_SAVE_CONTEXT()` was only used in `GREATEST_RUN_TEST`,
+not `GREATEST_RUN_TEST1` or `GREATEST_RUN_TESTp`, which could cause
+corruption when tests using them called `ASSERT_OR_LONGJMPm` or
+`FAIL_WITH_LONGJMPm`. Reported and fixed by @tcarmelveilleux.
+
+Add `contrib/entapment` script, which converts a greatest test runner's
+verbose-style output to TAP version 13 format.
+
+Add `contrib/testify` script, which converts calls to `RUN_TEST(test);`
+to test functions with `SKIPm("TODO");`.
+
+Disabled `-Weverything` in Makefile: it isn't portable.
+
+Various improvements to the documentation.
+
+If list (`-l`) and test name filtering are both used, only tests that
+would have run are printed. This can be used to test filter strings.
+
+
+## v1.2.2 - 2017-04-26
+
+### API Changes
+
+None.
+
+
+### Other Improvements
+
+Explicitly mention ISC License in README.
+
+Always `fflush(GREATEST_STDOUT)` after tests, rather than checking
+whether `GREATEST_STDOUT` expands to `stdout` (the default) first. This
+avoids a tautological comparison warning. Reported by @jibsen and
+@nemequ.
+
+Address warnings that can appear under `-Weverything`: padding in
+`struct greatest_run_info`, a pointer cast that unintentionally removed
+`const`, and a non-literal `printf` format string (caused by a literal
+format string constructed and saved to a variable in a macro). Reported
+by @kozross.
+
+
+## v1.2.1 - 2016-06-25
+
+### API Changes
+
+None.
+
+
+### Other Improvements
+
+Accept "--help" as an alternate form of "-h" in command line test
+runners. (Thanks @jibsen).
+
+Avoid redundant evaluation of arguments in `ASSERT_ENUM_EQ`.
+
+Clarify type of `ENUM_STR` argument in `ASSERT_ENUM_EQ`. Use a function
+pointer typedef so the compiler can give better type errors.
+
+Warn about redundant evaluation of arguments in `ASSERT_EQ_FMT`.
+
+Prefix the variables used in the expansion of the `ASSERT_EQ_FMT`,
+`ASSERT_ENUM_EQ`, and `ASSERT_IN_RANGE` macros, to avoid name clashes
+that can cause confusing compiler errors.
+
+
+## v1.2.0 - 2016-06-06
+
+### API Changes
+
+Added `GREATEST_IGNORE_TEST`, which skips a test without warning about
+the function being unused.
+
+Added `GREATEST_ASSERT_STRN_EQ`, which does a string comparison with an
+explicit length (using `strncmp`, rather than `strcmp`).
+
+Added `GREATEST_ASSERT_MEM_EQ`, which does a memory comparison with an
+explicit length (using `memcmp`). If the memory differs, it will print a
+hexdump which highlights the lines and individual bytes which differ.
+(The `greenest` script was also updated to colorize the hexdump's
+difference markers.)
+
+Added `GREATEST_ASSERT_ENUM_EQ`, which compares two values and uses an
+enum-specific function to convert them to strings before printing
+failures.
+
+The `greenest` script has been moved into `contrib/`.
+
+
+### Other Improvements
+
+Fixed a bug that kept the `-f` (stop after first failure) flag from
+stopping the test runner immediately when a failure occured just
+before running a new suite.
+
+Added `extern "C" { ... }` guards for improved C++ compatibility.
+
+Fixed a warning when compiling as C++.
+
+Several updates to the README.
+
+A file with contribution guidelines (`CONTRIBUTING.md`) was added.
+
+
+## v1.1.1 - 2016-02-14
+
+### API Changes
+
+Align "Expected:"/"Got:" messages, so it's easier to compare values.
+
+
+### Other Improvements
+
+Fixed a bug that could lead to test suites running previous suites'
+setup/teardown callbacks. This was a bug in the optional suite support,
+so only v1.1.0 is affected.
+
+Updated the README to note that the `greenest` awk script expects
+a Unix-like environment (i.e., it doesn't work on Windows).
+
+
+## v1.1.0 - 2015-11-29
+
+### API Changes
+
+Made suites optional, so that `RUN_TEST` works outside of any suites.
+This reduces boilerplate in cases where there would only be one "main"
+suite anyway.
+
+Added `greatest_get_report()`, to populate a struct with the pass, fail,
+skip, and assertion counts, for cases where getting the counts directly
+is preferable to printing them with `GREATEST_PRINT_REPORT()` or
+`GREATEST_MAIN_END()` (i.e., without a CLI test runner).
+
+Added `greatest_set_test_filter(substring)` and
+`greatest_set_suite_filter(substring)`, so only tests or suites matching a
+filter substring can be run without using the CLI test runner.
+
+Added `greatest_set_flag()`, so the FIRST_FAIL flag can be set without
+using the CLI test runner.
+
+Added `SUITE_EXTERN` macro, for declaring suites in other compilation units.
+They could previously be declared using the `SUITE` macro, but this made a
+redundant declaration that could cause warnings.
+
+Added multiple levels of verbosity. Can be checked and set with
+`greatest_get_verbosity()`, and `greatest_set_verbosity()` respectively.
+(`GREATEST_IS_VERBOSE()` remains in the API.)
+
+Stop parsing CLI options if `--` is reached, so user code can include
+its own afterward.
+
+
+### Other Improvements
+
+Added the "Key Features" section to the README, and updated the
+tagline to reflect that greatest isn't specific to unit testing.
+
+Added this changelog.
+
+Added LICENSE file (ISC License), to match common project layouts.
+greatest already had its license in the `greatest.h` header, but this
+makes it easier to find at a glance.
+
+Added a URL for finding the newest version of greatest to the header.
+
+Updated the default report message: print "1 test", not "1 tests";
+print "X passed, Y failed," instead of "X pass, Y fail,", etc.
+
+Updated the CLI test runner's help message to reflect that the
+`-s` and `-t` switches match by substring, not the full name.
+
+Fixed C89 error due to incrementing assertion count before
+declaring variables (mixing declarations and code).
+
+Fixed warnings.
+
+
+### Known Issues
+
+The `greatest_printf_cb` callback in `struct greatest_type_info` type
+should have an extra `FILE *` argument (i.e., behave like fprintf, not
+printf). This leads to cases where `GREATEST_STDOUT` has been customized
+and `GREATEST_ASSERT_EQUAL_T`'s "Expected:", "Got:" messages are printed
+to the correct stream, but the callback still prints the values on
+stdout. Resolving this is an interface change, so it will have to wait
+until release v2.0.0. (The actual code change will be minor -- adding an
+extra f argument to the callback, and passing it to fprinf rather than
+using printf.)
+
+The `greatest_type_info` struct is typedef'd, which is inconsistent with
+the API otherwise not typedef-ing user facing structs. (It is also in the
+struct namespace.) Fixing this will have to wait until v2.0.0.
+
+
+## v1.0.0 - 2015-05-11
+
+### API Changes
+
+Added `ASSERT_EQ_FMT(expected, actual, format)` to compare scalar values and
+print them (if different) using the given format string (e.g. "0x%08x").
+
+Added `ASSERT_IN_RANGE(expected, actual, tolerance)` to check whether the
+actual value is within a +/- tolerance, as a floating point comparison,
+and print the actual value if out of bounds. The floating point type used
+can be configured by overriding GREATEST_FLOAT.
+
+Added `GREATEST_USE_TIME` compile-time #define, which can be set to 0
+to compile out all time.h / clock() related functionality.
+
+Added check for `_MSC_VER`, to detect C99 compatibility when built with
+Visual Studio.
+
+
+## v0.11.1 - 2015-01-17
+
+Patch version, increased due to bug fixes (thanks @pmj):
+
+. Fix for issue #26 - must not longjmp to a context in an exited function.
+. Corrected use of non-prefixed FAILm() macro in ASSERT macros.
+. Avoid compile warnings about no previous definition of suite functions.
+
+
+## v0.11.0 - 2015-01-02
+
+### API Changes
+
+Added `CHECK_CALL()` macro, to wrap a function call that can fail a test.
+
+Added `ASSERT_OR_LONGJMP()` / `FAIL_WITH_LONGJMP()`, to longjmp(3) from
+failing functions rather than returning. This is optional, and can be
+compiled out by `#define`-ing `GREATEST_USE_LONGJMP` to 0.
+
+Restructured API so a CLI test runner is no longer necessary.
+`GREATEST_INIT()` and `GREATEST_PRINT_REPORT()` can be called directly.
+
+
+### Other Improvements
+
+Explicitly documented the protocol for calling functions from a test that
+themselves call ASSERT(), SKIP(), FAIL(), etc. Added an enum for the
+test return type.
+
+Fixed warnings, improved the documentation.
+
+
+## v0.10.1 - 2014-11-16
+
+Fixed error when compiled as C++ by adding `extern` to
+`greatest_type_info` struct.
+
+
+## v0.10.0 - 2014-10-12
+
+### API Changes
+
+Added `ASSERT_EQUAL_T`, for comparing arbitrary structs and printing
+them when they differ.
+
+
+### Other Improvements
+
+Added `greenest` awk script, to color output.
+
+
+## v0.9.4 - 2014-08-06
+
+Started counting the total number of assertions.
+
+Fixed warnings.
+
+
+## v0.9.3 - 2014-05-30
+
+### API Changes
+
+Changed filters for test (`-t`) and suite (`-s`) names to use substring
+search, rather than exact matches.
+
+Added `GREATEST_FAILURE_ABORT()`, to check whether the test runner is in
+first-fail (`-f`) mode and there have been failures.
+
+
+### Other Improvements
+
+Added check to always print a line break for "FAIL" messages, unless at
+column 0.
+
+
+## v0.9.2 - 2013-08-06
+
+### API Changes
+
+Added a C89-compatible form of parametric testing (`GREATEST_RUN_TEST1`).
+
+
+### Other Improvements
+
+Fixed warnings when compiled as C++.
+
+
+## v0.9.1 - 2013-07-14
+
+Added `-f` to usage line in documentation.
+
+Fixed warnings.
+
+
+## v0.9.0 - 2013-03-02
+
+### API Changes
+
+Added finish-at-first-failure (`-f`) to CLI test runner.
+
+Added suite-level setup/teardown hooks.
+
+
+### Other Improvements
+
+Fixed warnings.
+
+
+## v0.8 - 2012-04-08
+
+### API Changes
+
+Added help (`-h`) and list (`-l`) options to CLI test runner.
+
+Added `GREATEST_RUN_TESTp` for parametric testing in C99.
+
+Added `GREATEST_IS_VERBOSE()`, to check whether the verbose (`-v`) flag
+was set.
+
+Added `GREATEST_SET_TEARDOWN_CB()`, for setting a teardown callback.
+
+Added custom message forms of PASS, FAIL, SKIP, e.g. `PASSm()`.
+
+
+### Other Improvements
+
+Fixed warnings.
+
+
+## Pre-v0.8 - 2012-01-09
+
+Initial public release of project.
diff --git a/libs/greatest/CONTRIBUTING.md b/libs/greatest/CONTRIBUTING.md
new file mode 100644
index 0000000..a74a99b
--- /dev/null
+++ b/libs/greatest/CONTRIBUTING.md
@@ -0,0 +1,73 @@
+# Contributing to greatest
+
+Thanks for taking time to contribute to greatest!
+
+Please send patches or pull requests against the `develop` branch. This
+makes it easier to avoid interface changes until they can be reflected
+in version number updates.
+
+Sending changes via patch or pull request acknowledges that you are
+willing and able to contribute it under this project's license. (Please
+don't contribute code you aren't legally able to share.)
+
+
+## Bug Reports
+
+Please report bugs at [the Issues page](https://github.com/silentbicycle/greatest/issues).
+
+If you are reporting a bug, please include:
+
++ Your operating system name and version.
+
++ Your compiler version and target platform.
+
++ Any details about your local setup that might be helpful in
+ troubleshooting.
+
++ Detailed steps to reproduce the bug.
+
+
+## Documentation
+
+Improvements to the documentation are welcome. So are requests for
+clarification -- if the docs are unclear or misleading, that's a
+potential source of bugs.
+
+
+## Portability
+
+greatest tries to assume little about its environment. It targets ANSI C
+(C89) as a baseline, and features that are specific to C99 or later need
+to be wrapped in a version check.
+
+It doesn't require a particular OS, or that there is an OS at all. (It
+may be running tests on an embedded system without an RTOS.) It uses
+`fprintf(3)` for reporting, that's about it.
+
+Improvements that don't fit the portability requirements can go in
+`contrib/`, just not the main `greatest.h` header.
+
+
+## contrib/: Extensions and Other Tools
+
+There is a `contrib/` directory for extensions. This could include
+scripts that generate test templates, add formatting to the reports, or
+better integrate greatest into build / continuous integration systems.
+Extension libraries that depend on dynamic allocation or
+platform-specific features can also go here.
+
+Please include a license in any standalone scripts or extensions.
+
+
+## Versioning & Compatibility
+
+The versioning format is MAJOR.MINOR.PATCH.
+
+Improvements or minor bug fixes that do not break compatibility with
+past releases lead to patch version increases. API changes that do not
+break compatibility lead to minor version increases and reset the patch
+version, and changes that do break compatibility lead to a major version
+increase.
+
+The version will be increased during the merge to master, as part of
+the release process.
diff --git a/libs/greatest/LICENSE b/libs/greatest/LICENSE
new file mode 100644
index 0000000..2fdef96
--- /dev/null
+++ b/libs/greatest/LICENSE
@@ -0,0 +1,13 @@
+Copyright (c) 2011-2018 Scott Vokes <vokes.s@gmail.com>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/libs/greatest/Makefile b/libs/greatest/Makefile
new file mode 100644
index 0000000..24c1881
--- /dev/null
+++ b/libs/greatest/Makefile
@@ -0,0 +1,52 @@
+# Warning flags for C and C++:
+COMMON_FLAGS += -Wall -Wextra -pedantic -Werror
+COMMON_FLAGS += -Wmissing-declarations -g
+#COMMON_FLAGS += -Weverything
+
+CFLAGS += ${COMMON_FLAGS}
+CPPFLAGS += ${COMMON_FLAGS}
+
+# These warnings are not valid for C++:
+CFLAGS += -Wmissing-prototypes
+CFLAGS += -Wstrict-prototypes
+
+PROGRAMS_C= example example_no_suite example_no_runner \
+ example_shuffle example_trunc
+PROGRAMS_CPP= example_cpp
+
+# Uncomment to demo c99 parametric testing.
+#CFLAGS += -std=c99
+
+# Uncomment to enable setjmp()/longjmp().
+#CFLAGS += -DGREATEST_USE_LONGJMP=1
+
+# Uncomment to disable clock() / time.h.
+#CFLAGS += -DGREATEST_USE_TIME=0
+
+all: all_c
+
+all_c: ${PROGRAMS_C}
+all_cpp: ${PROGRAMS_CPP}
+
+example: example.o example_suite.o
+example_no_suite: example_no_suite.o
+example_no_runner: example_no_runner.o
+example_shuffle: example_shuffle.o
+example_trunc: example_trunc.o
+
+*.o: greatest.h Makefile
+
+example_cpp: example_cpp.cpp greatest.h Makefile
+ ${CXX} -o $@ example_cpp.cpp ${CPPFLAGS} ${LDFLAGS}
+
+%.o: %.c
+ ${CC} -c -o $@ ${CFLAGS} $<
+
+%.o: %.cpp
+ ${CXX} -c -o $@ ${CPPFLAGS} $<
+
+%: %.o
+ ${CC} -o $@ ${LDFLAGS} $^
+
+clean:
+ rm -f ${PROGRAMS_C} ${PROGRAMS_CPP} *.o *.core
diff --git a/libs/greatest/README.md b/libs/greatest/README.md
new file mode 100644
index 0000000..f1ba127
--- /dev/null
+++ b/libs/greatest/README.md
@@ -0,0 +1,475 @@
+# greatest
+
+A testing system for C, contained in 1 header file.
+
+
+## Key Features and Project Goals
+
+- **Small, Portable, Lightweight**
+
+ greatest doesn't depend on anything beyond ANSI C89, and the test
+ scaffolding should build without warnings when compiled with
+ `-Wall -Wextra -pedantic`. It is under 1,000 LOC (SLOCCount),
+ and does no dynamic allocation.
+
+- **Permissive License**
+
+ greatest is released under the [ISC License][ISC]. You can use it
+ freely, even for commercial purposes.
+
+- **Easy To Set Up**
+
+ To use, just `#include "greatest.h"` in your project. There is
+ very little boilerplate. Most features are optional.
+
+- **Un-Opinionated**
+
+ When a command-line test runner is useful, greatest can provide one,
+ but it can also run as part of other programs. It doesn't depend on
+ a particular build system or other tooling, and should accommodate a
+ variety of testing approaches. It actively avoids imposing
+ architectural choices on code under test. While greatest was
+ designed with C in mind, it attempts to be usable from C++.
+
+- **Modular**
+
+ Tests can be run individually, or grouped into suites. Suites can
+ share common setup, and can be in distinct compilation units.
+
+- **Low Friction**
+
+ Specific tests or suites can be run by name, for focused and rapid
+ iteration during development. greatest adds very little startup
+ latency.
+
+
+There are some compile-time options, and slightly nicer syntax for
+parametric testing (running tests with arguments) if compiled
+with a C99 or later language standard.
+
+I wrote a
+[blog post](http://spin.atomicobject.com/2013/07/31/greatest-c-testing-embedded/)
+with more information. While it's several years old, it's still accurate
+about the main functionality.
+
+[theft][], a related project, adds [property-based testing][pbt].
+
+[1]: http://spin.atomicobject.com/2013/07/31/greatest-c-testing-embedded/
+[theft]: https://github.com/silentbicycle/theft
+[pbt]: https://spin.atomicobject.com/2014/09/17/property-based-testing-c/
+[ISC]: https://opensource.org/licenses/ISC
+
+## Basic Usage
+
+```c
+#include "greatest.h"
+
+/* A test runs various assertions, then calls PASS(), FAIL(), or SKIP(). */
+TEST x_should_equal_1(void) {
+ int x = 1;
+ /* Compare, with an automatic "1 != x" failure message */
+ ASSERT_EQ(1, x);
+
+ /* Compare, with a custom failure message */
+ ASSERT_EQm("Yikes, x doesn't equal 1", 1, x);
+
+ /* Compare, and if they differ, print both values,
+ * formatted like `printf("Expected: %d\nGot: %d\n", 1, x);` */
+ ASSERT_EQ_FMT(1, x, "%d");
+ PASS();
+}
+
+/* Suites can group multiple tests with common setup. */
+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 options, initialization. */
+
+ /* Individual tests can be run directly in main, outside of suites. */
+ /* RUN_TEST(x_should_equal_1); */
+
+ /* Tests can also be gathered into test suites. */
+ RUN_SUITE(the_suite);
+
+ GREATEST_MAIN_END(); /* display results */
+}
+```
+
+Output:
+
+```sh
+$ make simple && ./simple
+cc -g -Wall -Werror -pedantic simple.c -o simple
+
+* Suite the_suite:
+.
+1 test - 1 passed, 0 failed, 0 skipped (5 ticks, 0.000 sec)
+
+Total: 1 test (47 ticks, 0.000 sec), 3 assertions
+Pass: 1, fail: 0, skip: 0.
+```
+
+Tests are run with `RUN_TEST(test_name)`, which can be called directly
+from the test runner's `main` function or grouped into suites (which are
+run with `RUN_SUITE(suite_name)`). (Calls to `RUN_TEST` from inside
+another test are ignored.)
+
+Test cases can be run with arguments: `RUN_TEST1(test_name, arg)` passes
+a single argument, and if C99 features are supported, then
+`RUN_TESTp(test_name, ...)` uses `__VA_ARGS__` to run a test case with
+one or mare arguments. `greatest_set_test_suffix` sets a name suffix, so
+output from the test runner can include info about arguments.
+
+Test cases should call assertions and then end with `PASS()`, `SKIP()`,
+`FAIL()`, or their custom message variants (e.g. `SKIPm("TODO");`).
+If there are any test failures, the test runner will return 1,
+otherwise it will return 0. (Skips do not cause the test runner to
+report failure.)
+
+`PASS()`, `SKIP()`, `FAIL()`, and their custom message variants are
+macros that updating internal bookkeeping and then returning and enum
+value, such as `GREATEST_TEST_RES_FAIL`. They all `return` from the
+current test case function.
+
+`PASS()`/`PASSm("msg")` prints as a dot when verbosity is zero, or
+the test name and custom message (if any) with verbosity >= 1.
+
+`FAIL()`/`FAILm("msg")` always prints "FAIL test_name: msg file:line".
+
+`SKIP()`/`SKIPm("msg")` prints as an 's' when verbosity is zero, or the
+test name and custom message (if any) with verbosity >= 1. Because skips
+are not treated as a failure by the test runner, they can be used to
+skip test cases that aren't relevant in a particular build or
+environment, a way to temporarily disable broken tests, or as a sort of
+todo list for tests and functionality under active development.
+
+Tests and suites are just functions, so normal C scoping rules apply.
+For example, a test or suite named `main` will have a name collision.
+
+(For more examples, look at `example.c` and `example_suite.c`.)
+
+
+## Filtering By Name
+
+greatest runs all tests by default, but can be configured to only run
+suites or tests whose names contain a filter string, and/or exclude
+tests whose name contains a filter string. When test name filtering and
+exclusion are used together, exclusion takes precedence.
+
+ void greatest_set_suite_filter(const char *name);
+ void greatest_set_test_filter(const char *name);
+ void greatest_set_test_exclude(const char *name);
+
+These correspond to the following command line test runner options:
+
+ `-s SUITE`: Only run suites whose names contain the string "SUITE"
+ `-t TEST`: Only run tests whose names contain the string "TEST"
+ `-x EXCLUDE`: Exclude tests whose names contain the string "EXCLUDE"
+
+For example, to run any tests with "tree" in the name, in suites with
+"pars" in the name (such as "parser"), but exclude any tests whose names
+also contain "slow":
+
+ ./test_project -s pars -t tree -x slow
+
+The string matching includes optional test name suffixes.
+
+The `greatest_set_exact_name_match()` function and corresponding `-e`
+command line runner flag can be used to only run tests and/or suites
+whose names exactly match the name filter(s). Note: exact-match suite
+filtering by name will not skip tests that are run outside of any suite.
+
+
+## Available Assertions
+
+Assertions fail the current test unless some condition holds. All
+assertions have a custom message variant (with an `m` suffix), which
+takes a message string as its first argument. For example, the
+assertion `ASSERT_EQ(apple, orange);` could instead be used like
+`ASSERT_EQm("these should match", apple, orange)`. Non-message
+assertions create a default message.
+
+
+### `ASSERT(COND)`
+
+Assert that `COND` evaluates to a true (non-zero) value.
+
+
+### `ASSERT_FALSE(COND)`
+
+Assert that `COND` evaluates to a false (zero) value.
+
+
+### `ASSERT_EQ(EXPECTED, ACTUAL)`
+
+Assert that `EXPECTED == ACTUAL`. To print the values if they
+differ, use `ASSERT_EQ_FMT`. To compare with custom equality test
+and print functions, use `ASSERT_EQUAL_T` instead.
+
+
+### `ASSERT_NEQ(EXPECTED, ACTUAL)`
+
+Assert that `EXPECTED != ACTUAL`.
+
+
+### `ASSERT_GT(EXPECTED, ACTUAL)`
+
+Assert that `EXPECTED > ACTUAL`.
+
+
+### `ASSERT_GTE(EXPECTED, ACTUAL)`
+
+Assert that `EXPECTED >= ACTUAL`.
+
+
+### `ASSERT_LT(EXPECTED, ACTUAL)`
+
+Assert that `EXPECTED < ACTUAL`.
+
+
+### `ASSERT_LTE(EXPECTED, ACTUAL)`
+
+Assert that `EXPECTED <= ACTUAL`.
+
+
+### `ASSERT_EQ_FMT(EXPECTED, ACTUAL, FORMAT)`
+
+Assert that `EXPECTED == ACTUAL`. If they are not equal, print their
+values using `FORMAT` as the `printf` format string.
+
+For example: `ASSERT_EQ_FMT(123, result, "%d");` will call `printf`
+like `printf("Expected: %d\nGot: %d\n", 123, result);` if its
+`EXPECTED` and `ACTUAL` arguments don't match.
+
+Note: `EXPECTED` and `ACTUAL` will be evaluated more than once on
+failure, so they should not be a function call with side effects.
+(Since their type is not known by the macro, they cannot be
+captured in a local variable. `typeof` is a GCC extension.)
+
+
+### `ASSERT_IN_RANGE(EXPECTED, ACTUAL, TOLERANCE)`
+
+Assert that `ACTUAL` is within `EXPECTED` +/- `TOLERANCE`, once the
+values have been converted to a configurable floating point type
+(`GREATEST_FLOAT`).
+
+greatest does not depent on floating point math.
+It is only used within `ASSERT_IN_RANGE`'s macro expansion.
+
+
+### `ASSERT_STR_EQ(EXPECTED, ACTUAL)`
+
+Assert that the strings are equal
+(i.e., `strcmp(EXPECTED, ACTUAL) == 0`).
+
+
+### `ASSERT_STRN_EQ(EXPECTED, ACTUAL, SIZE)`
+
+Assert that the first `SIZE` bytes of the strings are equal
+(i.e., `strncmp(EXPECTED, ACTUAL, SIZE) == 0`).
+
+
+### `ASSERT_MEM_EQ(EXPECTED, ACTUAL, SIZE)`
+
+Assert that the first `SIZE` bytes of memory pointed to by `EXPECTED`
+and `ACTUAL` are equal. If their memory differs, print a hexdump and
+highlight the lines and individual bytes which do not match.
+
+
+### `ASSERT_ENUM_EQ(EXPECTED, ACTUAL, ENUM_STR_FUN)`
+
+Assert that the enum value `EXPECTED` is equal to `ACTUAL`. If not,
+convert each enum value to a string using `ENUM_STR_FUN` before printing
+them.
+
+`ENUM_STR_FUN` should have a type like:
+
+ const char *FUN(int x);
+
+
+### `ASSERT_EQUAL_T(EXPECTED, ACTUAL, TYPE_INFO, UDATA)`
+
+Assert that `EXPECTED` and `ACTUAL` are equal, using the
+`greatest_equal_cb` function pointed to by `TYPE_INFO->equal` to compare
+them. The assertion's `UDATA` argument can be used to pass in arbitrary
+user data (or `NULL`) to the callbacks. If the values are not equal and
+the `TYPE_INFO->print` function is defined, it will be used to print an
+"Expected: X, Got: Y" message.
+
+
+### `ASSERT_OR_LONGJMP(COND)`
+
+Assert that `COND` evaluates to a true value. If not, then use
+`longjmp(3)` to immediately return from the test case and any
+intermediate function calls.
+
+If built with `GREATEST_USE_LONGJMP` `#define`d to 0, then all
+setjmp/longjmp-related functionality will be compiled out. This also
+reduces memory usage by `sizeof jmp_buf`, which may be several hundred
+bytes, depending on the platform.
+
+
+## Random Shuffling
+
+Groups of suites or tests can be run in shuffled order by using
+`GREATEST_SHUFFLE_SUITES` and `GREATEST_SHUFFLE_TESTS`, respectively.
+This can help find and eliminate accidental coupling between tests.
+
+The shuffling depends on the seed and the test/suite count, so a
+consistent seed will only lead to reproducible ordering until the
+group's count changes.
+
+Shuffling suites:
+
+ SHUFFLE_SUITES(seed, {
+ RUN_SUITE(suite1);
+ RUN_SUITE(suite2);
+ RUN_SUITE(suite3);
+ RUN_SUITE(suite4);
+ RUN_SUITE(suite5);
+ });
+
+Shuffling tests:
+
+ SHUFFLE_TESTS(seed, {
+ RUN_TEST(test_a);
+ RUN_TEST1(test_b, 12345);
+ RUN_TEST(test_c);
+ RUN_TESTp(test_d, "some_argument");
+ RUN_TEST(test_e);
+ });
+
+Note: Any other code inside the block will be executed several times.
+The shuffling macro expands to a loop with (count + 1) iterations -- the
+first pass counts, and the following passes only execute the next chosen
+suite/test. In particular, avoid running tests directly inside of a
+`SHUFFLE_SUITES` block without a suite, because the test will be run
+on each iteration.
+
+
+## Test Name Suffixes
+
+`greatest_set_test_suffix` can be used to set an optional name suffix
+for the next test:
+
+ for (i = 0; i < row_count; i++) {
+ const struct table_row *row = &table[row_count];
+ greatest_set_test_suffix(row->name);
+ RUN_TEST1(test_with_arg, row);
+ }
+
+This will cause the test name to print with a `_` separator and the
+suffix in all pass/fail/skip messages (i.e., `test_with_arg_KEY`). This
+is especially useful when running a test several times with different
+arguments, in shuffled order. The name suffix is included when using
+name-based filtering.
+
+The test name and optional suffix are copied into an internal buffer.
+Its size can be configured by `#define`ing the constant
+`GREATEST_TESTNAME_BUF_SIZE`. (If not `#define`d, it defaults to 128
+bytes.) If the buffer is not large enough for the name and suffix, it
+will truncate after `size - 1` bytes, to ensure that it is properly
+`\0`-terminated.
+
+The name suffix pointer is cleared after each `RUN_TEST*` call, so a
+suffix can be constructed in a stack allocated buffer without later
+dereferencing a pointer that has gone out of scope.
+
+
+## Sub-Functions
+
+Because of how `PASS()`, `ASSERT()`, `FAIL()`, etc. are implemented
+(returning a test result enum value), calls to functions that use them
+directly from test functions must be wrapped in `CHECK_CALL`:
+
+ TEST example_using_subfunctions(void) {
+ CHECK_CALL(less_than_three(5));
+ PASS();
+ }
+
+This is only necessary if the called function can cause test failures.
+The function should have a return type of `enum greatest_test_res`.
+
+
+## Command Line Options
+
+Test runners build with the following command line options:
+
+ Usage: (test_runner) [-hlfave] [-s SUITE] [-t TEST] [-x EXCLUDE]
+ -h, --help print this Help
+ -l List suites and tests, then exit (dry run)
+ -f Stop runner after first failure
+ -a Abort on first failure (implies -f)
+ -v Verbose output
+ -s SUITE only run suite w/ name containing substring SUITE
+ -t TEST only run test w/ name containing substring TEST
+ -e only run exact name match for -s or -t
+ -x EXCLUDE exclude tests containing string substring EXCLUDE
+
+Any arguments after `--` will be ignored.
+
+If you want to run multiple test suites in parallel, look at
+[parade](https://github.com/silentbicycle/parade).
+
+These command line options are processed by `GREATEST_MAIN_BEGIN();`.
+
+
+## Running Tests In Another Program
+
+Rather than producing a command line test runner (which checks the
+command line options, and exits with a pass/fail return code after
+running tests), greatest can be used more like a library. Instead of
+using `GREATEST_MAIN_BEGIN()`, use `GREATEST_INIT()` to (re-)initialize
+greatest, then use either `GREATEST_PRINT_REPORT()` to print the report
+to `GREATEST_STDOUT`, or use `greatest_get_report(&report)` to get the
+pass, fail, skip, and assertion counters.
+
+The command line flags above have corresponding functions:
+
+- `greatest_stop_at_first_fail()`
+- `greatest_abort_on_fail()`
+- `greatest_list_only()`
+- `greatest_set_exact_name_match()`
+- `greatest_set_suite_filter(const char *filter)`
+- `greatest_set_test_filter(const char *filter)`
+- `greatest_set_test_exclude(const char *filter)`
+- `greatest_get_verbosity()`
+- `greatest_set_verbosity(unsigned int verbosity)`
+
+
+## Aliases
+
+Most of the macros have prefixed and unprefixed forms. For example,
+`SUITE` is the same as `GREATEST_SUITE`.
+
+Check the source for the list -- search for `GREATEST_USE_ABBREVS`.
+
+These aliases can be disabled by `#define`-ing `GREATEST_USE_ABBREVS` to 0.
+
+
+## Color Output
+
+If you want color output (`PASS` in green, `FAIL` in red, etc.), you can
+pipe the output through the included `greenest` script in `contrib/`:
+
+```sh
+$ ./example -v | greenest
+```
+
+(Note that `greenest` depends on a Unix-like environment.)
+
+greatest itself doesn't have built-in coloring to stay small and portable.
+
+
+## TAP Format
+
+There is an awk script provided, `contrib/entapment`, that converts the
+verbose output from the default CLI test runner to TAP version 13
+format:
+
+ ./example -v | contrib/entapment
diff --git a/libs/greatest/contrib/entapment b/libs/greatest/contrib/entapment
new file mode 100644
index 0000000..8221ff9
--- /dev/null
+++ b/libs/greatest/contrib/entapment
@@ -0,0 +1,107 @@
+#!/usr/bin/awk -f
+######################################################################
+# Copyright (c) 2017 Scott Vokes <vokes.s@gmail.com>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+######################################################################
+#
+# This script converts greatest verbose output to TAP version 13.
+#
+# Usage:
+# test_runner -v | contrib/entapment
+#
+######################################################################
+
+BEGIN {
+ diag_i = 1
+
+ PASS = 0
+ FAIL = 1
+ SKIP = 2
+ TODO = 3
+}
+
+/^\* Suite/ {
+ suites[total_count] = $3
+}
+
+/^PASS/ {
+ total_count++
+ pass_count++
+ results[total_count] = PASS
+ $1 = ""
+ msg[total_count] = $0
+ next
+}
+
+/^FAIL/ {
+ total_count++
+ fail_count++
+ results[total_count] = FAIL
+ $1 = ""
+ msg[total_count] = $0
+ next
+}
+
+/^SKIP/ {
+ total_count++
+ if (match($0, "TODO")) {
+ results[total_count] = TODO
+ } else {
+ results[total_count] = SKIP
+ }
+ $1 = ""
+ msg[total_count] = $0
+ next
+}
+
+{
+ # Shift this by 1 so any test output is printed after ok/not ok line
+ if (diag_groups[total_count + 1] == 0) {
+ diag_groups[total_count + 1] = diag_lines
+ }
+ diag[diag_lines++] = $0
+}
+
+END {
+ diag_groups[total_count] = diag_lines
+
+ printf("TAP version 13\n")
+ printf("%d..%d\n", 1, total_count)
+
+ for (i = 1; i <= total_count; i++) {
+ if (suites[i] != "") {
+ printf("# suite %s\n", suites[i])
+ }
+ if (results[i] == PASS) {
+ printf("ok %d -%s\n", i, msg[i])
+ } else if (results[i] == FAIL) {
+ printf("not ok %d -%s\n", i, msg[i])
+ } else if (results[i] == SKIP) {
+ printf("not ok %d # SKIP -%s\n", i, msg[i])
+ } else if (results[i] == TODO) {
+ printf("not ok %d # TODO -%s\n", i, msg[i])
+ }
+
+ if (diag_groups[i]) {
+ for (d = diag_groups[i]; d < diag_groups[i + 1]; d++) {
+ printf("# %s\n", diag[d])
+ }
+ }
+ }
+ if (total_count > 0) {
+ printf("# pass %d, fail %d, skip %d, %.2f%% okay\n",
+ pass_count, fail_count, total_count - (pass_count + fail_count),
+ 100 * (pass_count / total_count))
+ }
+}
diff --git a/libs/greatest/contrib/greenest b/libs/greatest/contrib/greenest
new file mode 100644
index 0000000..48d1218
--- /dev/null
+++ b/libs/greatest/contrib/greenest
@@ -0,0 +1,33 @@
+#!/usr/bin/awk -f
+# Copyright (c) 2016 Scott Vokes <vokes.s@gmail.com>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+BEGIN {
+ GREEN = "\033[32m"
+ RED = "\033[31m"
+ YELLOW = "\033[33m"
+ RESET = "\033[m"
+}
+
+/^PASS/ { sub("PASS", GREEN "PASS" RESET) }
+/^SKIP/ { sub("SKIP", YELLOW "SKIP" RESET) }
+/^FAIL/ { sub("FAIL", RED "FAIL" RESET) }
+
+# highlight hexdump difference markers
+/^[0-9a-f]/ {
+ sub("X", GREEN "X" RESET, $2)
+ gsub("<", GREEN "<" RESET, $0)
+}
+
+{ print($0) }
diff --git a/libs/greatest/contrib/testify b/libs/greatest/contrib/testify
new file mode 100644
index 0000000..9a65367
--- /dev/null
+++ b/libs/greatest/contrib/testify
@@ -0,0 +1,33 @@
+#!/usr/bin/awk -f
+# Copyright (c) 2017 Scott Vokes <vokes.s@gmail.com>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+# This is a script that reads a bunch of lines like:
+# RUN_TEST(test_name);
+# RUN_TEST(other_name);
+#
+# and outputs
+# TEST test_name(void) {
+# SKIPm("TODO");
+# }
+#
+# TEST other_name(void) {
+# SKIPm("TODO");
+# }
+
+/RUN_TEST\(/ {
+ split($1, test, /\(|\)/)
+ name = test[2]
+ printf("TEST %s(void) {\n SKIPm(\"TODO\");\n}\n\n", name)
+}
diff --git a/libs/greatest/greatest.h b/libs/greatest/greatest.h
new file mode 100644
index 0000000..af0c053
--- /dev/null
+++ b/libs/greatest/greatest.h
@@ -0,0 +1,1266 @@
+/*
+ * Copyright (c) 2011-2021 Scott Vokes <vokes.s@gmail.com>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef GREATEST_H
+#define GREATEST_H
+
+#if defined(__cplusplus) && !defined(GREATEST_NO_EXTERN_CPLUSPLUS)
+extern "C" {
+#endif
+
+/* 1.5.0 */
+#define GREATEST_VERSION_MAJOR 1
+#define GREATEST_VERSION_MINOR 5
+#define GREATEST_VERSION_PATCH 0
+
+/* A unit testing system for C, contained in 1 file.
+ * It doesn't use dynamic allocation or depend on anything
+ * beyond ANSI C89.
+ *
+ * An up-to-date version can be found at:
+ * https://github.com/silentbicycle/greatest/
+ */
+
+
+/*********************************************************************
+ * Minimal test runner template
+ *********************************************************************/
+#if 0
+
+#include "greatest.h"
+
+TEST foo_should_foo(void) {
+ PASS();
+}
+
+static void setup_cb(void *data) {
+ printf("setup callback for each test case\n");
+}
+
+static void teardown_cb(void *data) {
+ printf("teardown callback for each test case\n");
+}
+
+SUITE(suite) {
+ /* Optional setup/teardown callbacks which will be run before/after
+ * every test case. If using a test suite, they will be cleared when
+ * the suite finishes. */
+ SET_SETUP(setup_cb, voidp_to_callback_data);
+ SET_TEARDOWN(teardown_cb, voidp_to_callback_data);
+
+ RUN_TEST(foo_should_foo);
+}
+
+/* Add definitions that need to be in the test runner's main file. */
+GREATEST_MAIN_DEFS();
+
+/* Set up, run suite(s) of tests, report pass/fail/skip stats. */
+int run_tests(void) {
+ GREATEST_INIT(); /* init. greatest internals */
+ /* List of suites to run (if any). */
+ RUN_SUITE(suite);
+
+ /* Tests can also be run directly, without using test suites. */
+ RUN_TEST(foo_should_foo);
+
+ GREATEST_PRINT_REPORT(); /* display results */
+ return greatest_all_passed();
+}
+
+/* main(), for a standalone command-line test runner.
+ * This replaces run_tests above, and adds command line option
+ * handling and exiting with a pass/fail status. */
+int main(int argc, char **argv) {
+ GREATEST_MAIN_BEGIN(); /* init & parse command-line args */
+ RUN_SUITE(suite);
+ GREATEST_MAIN_END(); /* display results */
+}
+
+#endif
+/*********************************************************************/
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+/***********
+ * Options *
+ ***********/
+
+/* Default column width for non-verbose output. */
+#ifndef GREATEST_DEFAULT_WIDTH
+#define GREATEST_DEFAULT_WIDTH 72
+#endif
+
+/* FILE *, for test logging. */
+#ifndef GREATEST_STDOUT
+#define GREATEST_STDOUT stdout
+#endif
+
+/* Remove GREATEST_ prefix from most commonly used symbols? */
+#ifndef GREATEST_USE_ABBREVS
+#define GREATEST_USE_ABBREVS 1
+#endif
+
+/* Set to 0 to disable all use of setjmp/longjmp. */
+#ifndef GREATEST_USE_LONGJMP
+#define GREATEST_USE_LONGJMP 0
+#endif
+
+/* Make it possible to replace fprintf with another
+ * function with the same interface. */
+#ifndef GREATEST_FPRINTF
+#define GREATEST_FPRINTF fprintf
+#endif
+
+#if GREATEST_USE_LONGJMP
+#include <setjmp.h>
+#endif
+
+/* Set to 0 to disable all use of time.h / clock(). */
+#ifndef GREATEST_USE_TIME
+#define GREATEST_USE_TIME 1
+#endif
+
+#if GREATEST_USE_TIME
+#include <time.h>
+#endif
+
+/* Floating point type, for ASSERT_IN_RANGE. */
+#ifndef GREATEST_FLOAT
+#define GREATEST_FLOAT double
+#define GREATEST_FLOAT_FMT "%g"
+#endif
+
+/* Size of buffer for test name + optional '_' separator and suffix */
+#ifndef GREATEST_TESTNAME_BUF_SIZE
+#define GREATEST_TESTNAME_BUF_SIZE 128
+#endif
+
+
+/*********
+ * Types *
+ *********/
+
+/* Info for the current running suite. */
+typedef struct greatest_suite_info {
+ unsigned int tests_run;
+ unsigned int passed;
+ unsigned int failed;
+ unsigned int skipped;
+
+#if GREATEST_USE_TIME
+ /* timers, pre/post running suite and individual tests */
+ clock_t pre_suite;
+ clock_t post_suite;
+ clock_t pre_test;
+ clock_t post_test;
+#endif
+} greatest_suite_info;
+
+/* Type for a suite function. */
+typedef void greatest_suite_cb(void);
+
+/* Types for setup/teardown callbacks. If non-NULL, these will be run
+ * and passed the pointer to their additional data. */
+typedef void greatest_setup_cb(void *udata);
+typedef void greatest_teardown_cb(void *udata);
+
+/* Type for an equality comparison between two pointers of the same type.
+ * Should return non-0 if equal, otherwise 0.
+ * UDATA is a closure value, passed through from ASSERT_EQUAL_T[m]. */
+typedef int greatest_equal_cb(const void *expd, const void *got, void *udata);
+
+/* Type for a callback that prints a value pointed to by T.
+ * Return value has the same meaning as printf's.
+ * UDATA is a closure value, passed through from ASSERT_EQUAL_T[m]. */
+typedef int greatest_printf_cb(const void *t, void *udata);
+
+/* Callbacks for an arbitrary type; needed for type-specific
+ * comparisons via GREATEST_ASSERT_EQUAL_T[m].*/
+typedef struct greatest_type_info {
+ greatest_equal_cb *equal;
+ greatest_printf_cb *print;
+} greatest_type_info;
+
+typedef struct greatest_memory_cmp_env {
+ const unsigned char *exp;
+ const unsigned char *got;
+ size_t size;
+} greatest_memory_cmp_env;
+
+/* Callbacks for string and raw memory types. */
+extern greatest_type_info greatest_type_info_string;
+extern greatest_type_info greatest_type_info_memory;
+
+typedef enum {
+ GREATEST_FLAG_FIRST_FAIL = 0x01,
+ GREATEST_FLAG_LIST_ONLY = 0x02,
+ GREATEST_FLAG_ABORT_ON_FAIL = 0x04
+} greatest_flag_t;
+
+/* Internal state for a PRNG, used to shuffle test order. */
+struct greatest_prng {
+ unsigned char random_order; /* use random ordering? */
+ unsigned char initialized; /* is random ordering initialized? */
+ unsigned char pad_0[6];
+ unsigned long state; /* PRNG state */
+ unsigned long count; /* how many tests, this pass */
+ unsigned long count_ceil; /* total number of tests */
+ unsigned long count_run; /* total tests run */
+ unsigned long a; /* LCG multiplier */
+ unsigned long c; /* LCG increment */
+ unsigned long m; /* LCG modulus, based on count_ceil */
+};
+
+/* Struct containing all test runner state. */
+typedef struct greatest_run_info {
+ unsigned char flags;
+ unsigned char verbosity;
+ unsigned char running_test; /* guard for nested RUN_TEST calls */
+ unsigned char exact_name_match;
+
+ unsigned int tests_run; /* total test count */
+
+ /* currently running test suite */
+ greatest_suite_info suite;
+
+ /* overall pass/fail/skip counts */
+ unsigned int passed;
+ unsigned int failed;
+ unsigned int skipped;
+ unsigned int assertions;
+
+ /* info to print about the most recent failure */
+ unsigned int fail_line;
+ unsigned int pad_1;
+ const char *fail_file;
+ const char *msg;
+
+ /* current setup/teardown hooks and userdata */
+ greatest_setup_cb *setup;
+ void *setup_udata;
+ greatest_teardown_cb *teardown;
+ void *teardown_udata;
+
+ /* formatting info for ".....s...F"-style output */
+ unsigned int col;
+ unsigned int width;
+
+ /* only run a specific suite or test */
+ const char *suite_filter;
+ const char *test_filter;
+ const char *test_exclude;
+ const char *name_suffix; /* print suffix with test name */
+ char name_buf[GREATEST_TESTNAME_BUF_SIZE];
+
+ struct greatest_prng prng[2]; /* 0: suites, 1: tests */
+
+#if GREATEST_USE_TIME
+ /* overall timers */
+ clock_t begin;
+ clock_t end;
+#endif
+
+#if GREATEST_USE_LONGJMP
+ int pad_jmp_buf;
+ unsigned char pad_2[4];
+ jmp_buf jump_dest;
+#endif
+} greatest_run_info;
+
+struct greatest_report_t {
+ /* overall pass/fail/skip counts */
+ unsigned int passed;
+ unsigned int failed;
+ unsigned int skipped;
+ unsigned int assertions;
+};
+
+/* Global var for the current testing context.
+ * Initialized by GREATEST_MAIN_DEFS(). */
+extern greatest_run_info greatest_info;
+
+/* Type for ASSERT_ENUM_EQ's ENUM_STR argument. */
+typedef const char *greatest_enum_str_fun(int value);
+
+
+/**********************
+ * Exported functions *
+ **********************/
+
+/* These are used internally by greatest macros. */
+int greatest_test_pre(const char *name);
+void greatest_test_post(int res);
+int greatest_do_assert_equal_t(const void *expd, const void *got,
+ greatest_type_info *type_info, void *udata);
+void greatest_prng_init_first_pass(int id);
+int greatest_prng_init_second_pass(int id, unsigned long seed);
+void greatest_prng_step(int id);
+
+/* These are part of the public greatest API. */
+void GREATEST_SET_SETUP_CB(greatest_setup_cb *cb, void *udata);
+void GREATEST_SET_TEARDOWN_CB(greatest_teardown_cb *cb, void *udata);
+void GREATEST_INIT(void);
+void GREATEST_PRINT_REPORT(void);
+int greatest_all_passed(void);
+void greatest_set_suite_filter(const char *filter);
+void greatest_set_test_filter(const char *filter);
+void greatest_set_test_exclude(const char *filter);
+void greatest_set_exact_name_match(void);
+void greatest_stop_at_first_fail(void);
+void greatest_abort_on_fail(void);
+void greatest_list_only(void);
+void greatest_get_report(struct greatest_report_t *report);
+unsigned int greatest_get_verbosity(void);
+void greatest_set_verbosity(unsigned int verbosity);
+void greatest_set_flag(greatest_flag_t flag);
+void greatest_set_test_suffix(const char *suffix);
+
+
+/********************
+* Language Support *
+********************/
+
+/* If __VA_ARGS__ (C99) is supported, allow parametric testing
+* without needing to manually manage the argument struct. */
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 19901L) || \
+ (defined(_MSC_VER) && _MSC_VER >= 1800)
+#define GREATEST_VA_ARGS
+#endif
+
+
+/**********
+ * Macros *
+ **********/
+
+/* Define a suite. (The duplication is intentional -- it eliminates
+ * a warning from -Wmissing-declarations.) */
+#define GREATEST_SUITE(NAME) void NAME(void); void NAME(void)
+
+/* Declare a suite, provided by another compilation unit. */
+#define GREATEST_SUITE_EXTERN(NAME) void NAME(void)
+
+/* Start defining a test function.
+ * The arguments are not included, to allow parametric testing. */
+#define GREATEST_TEST static enum greatest_test_res
+
+/* PASS/FAIL/SKIP result from a test. Used internally. */
+typedef enum greatest_test_res {
+ GREATEST_TEST_RES_PASS = 0,
+ GREATEST_TEST_RES_FAIL = -1,
+ GREATEST_TEST_RES_SKIP = 1
+} greatest_test_res;
+
+/* Run a suite. */
+#define GREATEST_RUN_SUITE(S_NAME) greatest_run_suite(S_NAME, #S_NAME)
+
+/* Run a test in the current suite. */
+#define GREATEST_RUN_TEST(TEST) \
+ do { \
+ if (greatest_test_pre(#TEST) == 1) { \
+ enum greatest_test_res res = GREATEST_SAVE_CONTEXT(); \
+ if (res == GREATEST_TEST_RES_PASS) { \
+ res = TEST(); \
+ } \
+ greatest_test_post(res); \
+ } \
+ } while (0)
+
+/* Ignore a test, don't warn about it being unused. */
+#define GREATEST_IGNORE_TEST(TEST) (void)TEST
+
+/* Run a test in the current suite with one void * argument,
+ * which can be a pointer to a struct with multiple arguments. */
+#define GREATEST_RUN_TEST1(TEST, ENV) \
+ do { \
+ if (greatest_test_pre(#TEST) == 1) { \
+ enum greatest_test_res res = GREATEST_SAVE_CONTEXT(); \
+ if (res == GREATEST_TEST_RES_PASS) { \
+ res = TEST(ENV); \
+ } \
+ greatest_test_post(res); \
+ } \
+ } while (0)
+
+#ifdef GREATEST_VA_ARGS
+#define GREATEST_RUN_TESTp(TEST, ...) \
+ do { \
+ if (greatest_test_pre(#TEST) == 1) { \
+ enum greatest_test_res res = GREATEST_SAVE_CONTEXT(); \
+ if (res == GREATEST_TEST_RES_PASS) { \
+ res = TEST(__VA_ARGS__); \
+ } \
+ greatest_test_post(res); \
+ } \
+ } while (0)
+#endif
+
+
+/* Check if the test runner is in verbose mode. */
+#define GREATEST_IS_VERBOSE() ((greatest_info.verbosity) > 0)
+#define GREATEST_LIST_ONLY() \
+ (greatest_info.flags & GREATEST_FLAG_LIST_ONLY)
+#define GREATEST_FIRST_FAIL() \
+ (greatest_info.flags & GREATEST_FLAG_FIRST_FAIL)
+#define GREATEST_ABORT_ON_FAIL() \
+ (greatest_info.flags & GREATEST_FLAG_ABORT_ON_FAIL)
+#define GREATEST_FAILURE_ABORT() \
+ (GREATEST_FIRST_FAIL() && \
+ (greatest_info.suite.failed > 0 || greatest_info.failed > 0))
+
+/* Message-less forms of tests defined below. */
+#define GREATEST_PASS() GREATEST_PASSm(NULL)
+#define GREATEST_FAIL() GREATEST_FAILm(NULL)
+#define GREATEST_SKIP() GREATEST_SKIPm(NULL)
+#define GREATEST_ASSERT(COND) \
+ GREATEST_ASSERTm(#COND, COND)
+#define GREATEST_ASSERT_OR_LONGJMP(COND) \
+ GREATEST_ASSERT_OR_LONGJMPm(#COND, COND)
+#define GREATEST_ASSERT_FALSE(COND) \
+ GREATEST_ASSERT_FALSEm(#COND, COND)
+#define GREATEST_ASSERT_EQ(EXP, GOT) \
+ GREATEST_ASSERT_EQm(#EXP " != " #GOT, EXP, GOT)
+#define GREATEST_ASSERT_NEQ(EXP, GOT) \
+ GREATEST_ASSERT_NEQm(#EXP " == " #GOT, EXP, GOT)
+#define GREATEST_ASSERT_GT(EXP, GOT) \
+ GREATEST_ASSERT_GTm(#EXP " <= " #GOT, EXP, GOT)
+#define GREATEST_ASSERT_GTE(EXP, GOT) \
+ GREATEST_ASSERT_GTEm(#EXP " < " #GOT, EXP, GOT)
+#define GREATEST_ASSERT_LT(EXP, GOT) \
+ GREATEST_ASSERT_LTm(#EXP " >= " #GOT, EXP, GOT)
+#define GREATEST_ASSERT_LTE(EXP, GOT) \
+ GREATEST_ASSERT_LTEm(#EXP " > " #GOT, EXP, GOT)
+#define GREATEST_ASSERT_EQ_FMT(EXP, GOT, FMT) \
+ GREATEST_ASSERT_EQ_FMTm(#EXP " != " #GOT, EXP, GOT, FMT)
+#define GREATEST_ASSERT_IN_RANGE(EXP, GOT, TOL) \
+ GREATEST_ASSERT_IN_RANGEm(#EXP " != " #GOT " +/- " #TOL, EXP, GOT, TOL)
+#define GREATEST_ASSERT_EQUAL_T(EXP, GOT, TYPE_INFO, UDATA) \
+ GREATEST_ASSERT_EQUAL_Tm(#EXP " != " #GOT, EXP, GOT, TYPE_INFO, UDATA)
+#define GREATEST_ASSERT_STR_EQ(EXP, GOT) \
+ GREATEST_ASSERT_STR_EQm(#EXP " != " #GOT, EXP, GOT)
+#define GREATEST_ASSERT_STRN_EQ(EXP, GOT, SIZE) \
+ GREATEST_ASSERT_STRN_EQm(#EXP " != " #GOT, EXP, GOT, SIZE)
+#define GREATEST_ASSERT_MEM_EQ(EXP, GOT, SIZE) \
+ GREATEST_ASSERT_MEM_EQm(#EXP " != " #GOT, EXP, GOT, SIZE)
+#define GREATEST_ASSERT_ENUM_EQ(EXP, GOT, ENUM_STR) \
+ GREATEST_ASSERT_ENUM_EQm(#EXP " != " #GOT, EXP, GOT, ENUM_STR)
+
+/* The following forms take an additional message argument first,
+ * to be displayed by the test runner. */
+
+/* Fail if a condition is not true, with message. */
+#define GREATEST_ASSERTm(MSG, COND) \
+ do { \
+ greatest_info.assertions++; \
+ if (!(COND)) { GREATEST_FAILm(MSG); } \
+ } while (0)
+
+/* Fail if a condition is not true, longjmping out of test. */
+#define GREATEST_ASSERT_OR_LONGJMPm(MSG, COND) \
+ do { \
+ greatest_info.assertions++; \
+ if (!(COND)) { GREATEST_FAIL_WITH_LONGJMPm(MSG); } \
+ } while (0)
+
+/* Fail if a condition is not false, with message. */
+#define GREATEST_ASSERT_FALSEm(MSG, COND) \
+ do { \
+ greatest_info.assertions++; \
+ if ((COND)) { GREATEST_FAILm(MSG); } \
+ } while (0)
+
+/* Internal macro for relational assertions */
+#define GREATEST__REL(REL, MSG, EXP, GOT) \
+ do { \
+ greatest_info.assertions++; \
+ if (!((EXP) REL (GOT))) { GREATEST_FAILm(MSG); } \
+ } while (0)
+
+/* Fail if EXP is not ==, !=, >, <, >=, or <= to GOT. */
+#define GREATEST_ASSERT_EQm(MSG,E,G) GREATEST__REL(==, MSG,E,G)
+#define GREATEST_ASSERT_NEQm(MSG,E,G) GREATEST__REL(!=, MSG,E,G)
+#define GREATEST_ASSERT_GTm(MSG,E,G) GREATEST__REL(>, MSG,E,G)
+#define GREATEST_ASSERT_GTEm(MSG,E,G) GREATEST__REL(>=, MSG,E,G)
+#define GREATEST_ASSERT_LTm(MSG,E,G) GREATEST__REL(<, MSG,E,G)
+#define GREATEST_ASSERT_LTEm(MSG,E,G) GREATEST__REL(<=, MSG,E,G)
+
+/* Fail if EXP != GOT (equality comparison by ==).
+ * Warning: FMT, EXP, and GOT will be evaluated more
+ * than once on failure. */
+#define GREATEST_ASSERT_EQ_FMTm(MSG, EXP, GOT, FMT) \
+ do { \
+ greatest_info.assertions++; \
+ if ((EXP) != (GOT)) { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\nExpected: "); \
+ GREATEST_FPRINTF(GREATEST_STDOUT, FMT, EXP); \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n Got: "); \
+ GREATEST_FPRINTF(GREATEST_STDOUT, FMT, GOT); \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n"); \
+ GREATEST_FAILm(MSG); \
+ } \
+ } while (0)
+
+/* Fail if EXP is not equal to GOT, printing enum IDs. */
+#define GREATEST_ASSERT_ENUM_EQm(MSG, EXP, GOT, ENUM_STR) \
+ do { \
+ int greatest_EXP = (int)(EXP); \
+ int greatest_GOT = (int)(GOT); \
+ greatest_enum_str_fun *greatest_ENUM_STR = ENUM_STR; \
+ if (greatest_EXP != greatest_GOT) { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\nExpected: %s", \
+ greatest_ENUM_STR(greatest_EXP)); \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n Got: %s\n", \
+ greatest_ENUM_STR(greatest_GOT)); \
+ GREATEST_FAILm(MSG); \
+ } \
+ } while (0) \
+
+/* Fail if GOT not in range of EXP +|- TOL. */
+#define GREATEST_ASSERT_IN_RANGEm(MSG, EXP, GOT, TOL) \
+ do { \
+ GREATEST_FLOAT greatest_EXP = (EXP); \
+ GREATEST_FLOAT greatest_GOT = (GOT); \
+ GREATEST_FLOAT greatest_TOL = (TOL); \
+ greatest_info.assertions++; \
+ if ((greatest_EXP > greatest_GOT && \
+ greatest_EXP - greatest_GOT > greatest_TOL) || \
+ (greatest_EXP < greatest_GOT && \
+ greatest_GOT - greatest_EXP > greatest_TOL)) { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, \
+ "\nExpected: " GREATEST_FLOAT_FMT \
+ " +/- " GREATEST_FLOAT_FMT \
+ "\n Got: " GREATEST_FLOAT_FMT \
+ "\n", \
+ greatest_EXP, greatest_TOL, greatest_GOT); \
+ GREATEST_FAILm(MSG); \
+ } \
+ } while (0)
+
+/* Fail if EXP is not equal to GOT, according to strcmp. */
+#define GREATEST_ASSERT_STR_EQm(MSG, EXP, GOT) \
+ do { \
+ GREATEST_ASSERT_EQUAL_Tm(MSG, EXP, GOT, \
+ &greatest_type_info_string, NULL); \
+ } while (0) \
+
+/* Fail if EXP is not equal to GOT, according to strncmp. */
+#define GREATEST_ASSERT_STRN_EQm(MSG, EXP, GOT, SIZE) \
+ do { \
+ size_t size = SIZE; \
+ GREATEST_ASSERT_EQUAL_Tm(MSG, EXP, GOT, \
+ &greatest_type_info_string, &size); \
+ } while (0) \
+
+/* Fail if EXP is not equal to GOT, according to memcmp. */
+#define GREATEST_ASSERT_MEM_EQm(MSG, EXP, GOT, SIZE) \
+ do { \
+ greatest_memory_cmp_env env; \
+ env.exp = (const unsigned char *)EXP; \
+ env.got = (const unsigned char *)GOT; \
+ env.size = SIZE; \
+ GREATEST_ASSERT_EQUAL_Tm(MSG, env.exp, env.got, \
+ &greatest_type_info_memory, &env); \
+ } while (0) \
+
+/* Fail if EXP is not equal to GOT, according to a comparison
+ * callback in TYPE_INFO. If they are not equal, optionally use a
+ * print callback in TYPE_INFO to print them. */
+#define GREATEST_ASSERT_EQUAL_Tm(MSG, EXP, GOT, TYPE_INFO, UDATA) \
+ do { \
+ greatest_type_info *type_info = (TYPE_INFO); \
+ greatest_info.assertions++; \
+ if (!greatest_do_assert_equal_t(EXP, GOT, \
+ type_info, UDATA)) { \
+ if (type_info == NULL || type_info->equal == NULL) { \
+ GREATEST_FAILm("type_info->equal callback missing!"); \
+ } else { \
+ GREATEST_FAILm(MSG); \
+ } \
+ } \
+ } while (0) \
+
+/* Pass. */
+#define GREATEST_PASSm(MSG) \
+ do { \
+ greatest_info.msg = MSG; \
+ return GREATEST_TEST_RES_PASS; \
+ } while (0)
+
+/* Fail. */
+#define GREATEST_FAILm(MSG) \
+ do { \
+ greatest_info.fail_file = __FILE__; \
+ greatest_info.fail_line = __LINE__; \
+ greatest_info.msg = MSG; \
+ if (GREATEST_ABORT_ON_FAIL()) { abort(); } \
+ return GREATEST_TEST_RES_FAIL; \
+ } while (0)
+
+/* Optional GREATEST_FAILm variant that longjmps. */
+#if GREATEST_USE_LONGJMP
+#define GREATEST_FAIL_WITH_LONGJMP() GREATEST_FAIL_WITH_LONGJMPm(NULL)
+#define GREATEST_FAIL_WITH_LONGJMPm(MSG) \
+ do { \
+ greatest_info.fail_file = __FILE__; \
+ greatest_info.fail_line = __LINE__; \
+ greatest_info.msg = MSG; \
+ longjmp(greatest_info.jump_dest, GREATEST_TEST_RES_FAIL); \
+ } while (0)
+#endif
+
+/* Skip the current test. */
+#define GREATEST_SKIPm(MSG) \
+ do { \
+ greatest_info.msg = MSG; \
+ return GREATEST_TEST_RES_SKIP; \
+ } while (0)
+
+/* Check the result of a subfunction using ASSERT, etc. */
+#define GREATEST_CHECK_CALL(RES) \
+ do { \
+ enum greatest_test_res greatest_RES = RES; \
+ if (greatest_RES != GREATEST_TEST_RES_PASS) { \
+ return greatest_RES; \
+ } \
+ } while (0) \
+
+#if GREATEST_USE_TIME
+#define GREATEST_SET_TIME(NAME) \
+ NAME = clock(); \
+ if (NAME == (clock_t) -1) { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, \
+ "clock error: %s\n", #NAME); \
+ exit(EXIT_FAILURE); \
+ }
+
+#define GREATEST_CLOCK_DIFF(C1, C2) \
+ GREATEST_FPRINTF(GREATEST_STDOUT, " (%lu ticks, %.3f sec)", \
+ (long unsigned int) (C2) - (long unsigned int)(C1), \
+ (double)((C2) - (C1)) / (1.0 * (double)CLOCKS_PER_SEC))
+#else
+#define GREATEST_SET_TIME(UNUSED)
+#define GREATEST_CLOCK_DIFF(UNUSED1, UNUSED2)
+#endif
+
+#if GREATEST_USE_LONGJMP
+#define GREATEST_SAVE_CONTEXT() \
+ /* setjmp returns 0 (GREATEST_TEST_RES_PASS) on first call * \
+ * so the test runs, then RES_FAIL from FAIL_WITH_LONGJMP. */ \
+ ((enum greatest_test_res)(setjmp(greatest_info.jump_dest)))
+#else
+#define GREATEST_SAVE_CONTEXT() \
+ /*a no-op, since setjmp/longjmp aren't being used */ \
+ GREATEST_TEST_RES_PASS
+#endif
+
+/* Run every suite / test function run within BODY in pseudo-random
+ * order, seeded by SEED. (The top 3 bits of the seed are ignored.)
+ *
+ * This should be called like:
+ * GREATEST_SHUFFLE_TESTS(seed, {
+ * GREATEST_RUN_TEST(some_test);
+ * GREATEST_RUN_TEST(some_other_test);
+ * GREATEST_RUN_TEST(yet_another_test);
+ * });
+ *
+ * Note that the body of the second argument will be evaluated
+ * multiple times. */
+#define GREATEST_SHUFFLE_SUITES(SD, BODY) GREATEST_SHUFFLE(0, SD, BODY)
+#define GREATEST_SHUFFLE_TESTS(SD, BODY) GREATEST_SHUFFLE(1, SD, BODY)
+#define GREATEST_SHUFFLE(ID, SD, BODY) \
+ do { \
+ struct greatest_prng *prng = &greatest_info.prng[ID]; \
+ greatest_prng_init_first_pass(ID); \
+ do { \
+ prng->count = 0; \
+ if (prng->initialized) { greatest_prng_step(ID); } \
+ BODY; \
+ if (!prng->initialized) { \
+ if (!greatest_prng_init_second_pass(ID, SD)) { break; } \
+ } else if (prng->count_run == prng->count_ceil) { \
+ break; \
+ } \
+ } while (!GREATEST_FAILURE_ABORT()); \
+ prng->count_run = prng->random_order = prng->initialized = 0; \
+ } while(0)
+
+/* Include several function definitions in the main test file. */
+#define GREATEST_MAIN_DEFS() \
+ \
+/* Is FILTER a subset of NAME? */ \
+static int greatest_name_match(const char *name, const char *filter, \
+ int res_if_none) { \
+ size_t offset = 0; \
+ size_t filter_len = filter ? strlen(filter) : 0; \
+ if (filter_len == 0) { return res_if_none; } /* no filter */ \
+ if (greatest_info.exact_name_match && strlen(name) != filter_len) { \
+ return 0; /* ignore substring matches */ \
+ } \
+ while (name[offset] != '\0') { \
+ if (name[offset] == filter[0]) { \
+ if (0 == strncmp(&name[offset], filter, filter_len)) { \
+ return 1; \
+ } \
+ } \
+ offset++; \
+ } \
+ \
+ return 0; \
+} \
+ \
+static void greatest_buffer_test_name(const char *name) { \
+ struct greatest_run_info *g = &greatest_info; \
+ size_t len = strlen(name), size = sizeof(g->name_buf); \
+ memset(g->name_buf, 0x00, size); \
+ (void)strncat(g->name_buf, name, size - 1); \
+ if (g->name_suffix && (len + 1 < size)) { \
+ g->name_buf[len] = '_'; \
+ strncat(&g->name_buf[len+1], g->name_suffix, size-(len+2)); \
+ } \
+} \
+ \
+/* Before running a test, check the name filtering and \
+ * test shuffling state, if applicable, and then call setup hooks. */ \
+int greatest_test_pre(const char *name) { \
+ struct greatest_run_info *g = &greatest_info; \
+ int match; \
+ greatest_buffer_test_name(name); \
+ match = greatest_name_match(g->name_buf, g->test_filter, 1) && \
+ !greatest_name_match(g->name_buf, g->test_exclude, 0); \
+ if (GREATEST_LIST_ONLY()) { /* just listing test names */ \
+ if (match) { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, " %s\n", g->name_buf); \
+ } \
+ goto clear; \
+ } \
+ if (match && (!GREATEST_FIRST_FAIL() || g->suite.failed == 0)) { \
+ struct greatest_prng *p = &g->prng[1]; \
+ if (p->random_order) { \
+ p->count++; \
+ if (!p->initialized || ((p->count - 1) != p->state)) { \
+ goto clear; /* don't run this test yet */ \
+ } \
+ } \
+ if (g->running_test) { \
+ fprintf(stderr, "Error: Test run inside another test.\n"); \
+ return 0; \
+ } \
+ GREATEST_SET_TIME(g->suite.pre_test); \
+ if (g->setup) { g->setup(g->setup_udata); } \
+ p->count_run++; \
+ g->running_test = 1; \
+ return 1; /* test should be run */ \
+ } else { \
+ goto clear; /* skipped */ \
+ } \
+clear: \
+ g->name_suffix = NULL; \
+ return 0; \
+} \
+ \
+static void greatest_do_pass(void) { \
+ struct greatest_run_info *g = &greatest_info; \
+ if (GREATEST_IS_VERBOSE()) { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "PASS %s: %s", \
+ g->name_buf, g->msg ? g->msg : ""); \
+ } else { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "."); \
+ } \
+ g->suite.passed++; \
+} \
+ \
+static void greatest_do_fail(void) { \
+ struct greatest_run_info *g = &greatest_info; \
+ if (GREATEST_IS_VERBOSE()) { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, \
+ "FAIL %s: %s (%s:%u)", g->name_buf, \
+ g->msg ? g->msg : "", g->fail_file, g->fail_line); \
+ } else { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "F"); \
+ g->col++; /* add linebreak if in line of '.'s */ \
+ if (g->col != 0) { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n"); \
+ g->col = 0; \
+ } \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "FAIL %s: %s (%s:%u)\n", \
+ g->name_buf, g->msg ? g->msg : "", \
+ g->fail_file, g->fail_line); \
+ } \
+ g->suite.failed++; \
+} \
+ \
+static void greatest_do_skip(void) { \
+ struct greatest_run_info *g = &greatest_info; \
+ if (GREATEST_IS_VERBOSE()) { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "SKIP %s: %s", \
+ g->name_buf, g->msg ? g->msg : ""); \
+ } else { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "s"); \
+ } \
+ g->suite.skipped++; \
+} \
+ \
+void greatest_test_post(int res) { \
+ GREATEST_SET_TIME(greatest_info.suite.post_test); \
+ if (greatest_info.teardown) { \
+ void *udata = greatest_info.teardown_udata; \
+ greatest_info.teardown(udata); \
+ } \
+ \
+ greatest_info.running_test = 0; \
+ if (res <= GREATEST_TEST_RES_FAIL) { \
+ greatest_do_fail(); \
+ } else if (res >= GREATEST_TEST_RES_SKIP) { \
+ greatest_do_skip(); \
+ } else if (res == GREATEST_TEST_RES_PASS) { \
+ greatest_do_pass(); \
+ } \
+ greatest_info.name_suffix = NULL; \
+ greatest_info.suite.tests_run++; \
+ greatest_info.col++; \
+ if (GREATEST_IS_VERBOSE()) { \
+ GREATEST_CLOCK_DIFF(greatest_info.suite.pre_test, \
+ greatest_info.suite.post_test); \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n"); \
+ } else if (greatest_info.col % greatest_info.width == 0) { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n"); \
+ greatest_info.col = 0; \
+ } \
+ fflush(GREATEST_STDOUT); \
+} \
+ \
+static void report_suite(void) { \
+ if (greatest_info.suite.tests_run > 0) { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, \
+ "\n%u test%s - %u passed, %u failed, %u skipped", \
+ greatest_info.suite.tests_run, \
+ greatest_info.suite.tests_run == 1 ? "" : "s", \
+ greatest_info.suite.passed, \
+ greatest_info.suite.failed, \
+ greatest_info.suite.skipped); \
+ GREATEST_CLOCK_DIFF(greatest_info.suite.pre_suite, \
+ greatest_info.suite.post_suite); \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n"); \
+ } \
+} \
+ \
+static void update_counts_and_reset_suite(void) { \
+ greatest_info.setup = NULL; \
+ greatest_info.setup_udata = NULL; \
+ greatest_info.teardown = NULL; \
+ greatest_info.teardown_udata = NULL; \
+ greatest_info.passed += greatest_info.suite.passed; \
+ greatest_info.failed += greatest_info.suite.failed; \
+ greatest_info.skipped += greatest_info.suite.skipped; \
+ greatest_info.tests_run += greatest_info.suite.tests_run; \
+ memset(&greatest_info.suite, 0, sizeof(greatest_info.suite)); \
+ greatest_info.col = 0; \
+} \
+ \
+static int greatest_suite_pre(const char *suite_name) { \
+ struct greatest_prng *p = &greatest_info.prng[0]; \
+ if (!greatest_name_match(suite_name, greatest_info.suite_filter, 1) \
+ || (GREATEST_FAILURE_ABORT())) { return 0; } \
+ if (p->random_order) { \
+ p->count++; \
+ if (!p->initialized || ((p->count - 1) != p->state)) { \
+ return 0; /* don't run this suite yet */ \
+ } \
+ } \
+ p->count_run++; \
+ update_counts_and_reset_suite(); \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n* Suite %s:\n", suite_name); \
+ GREATEST_SET_TIME(greatest_info.suite.pre_suite); \
+ return 1; \
+} \
+ \
+static void greatest_suite_post(void) { \
+ GREATEST_SET_TIME(greatest_info.suite.post_suite); \
+ report_suite(); \
+} \
+ \
+static void greatest_run_suite(greatest_suite_cb *suite_cb, \
+ const char *suite_name) { \
+ if (greatest_suite_pre(suite_name)) { \
+ suite_cb(); \
+ greatest_suite_post(); \
+ } \
+} \
+ \
+int greatest_do_assert_equal_t(const void *expd, const void *got, \
+ greatest_type_info *type_info, void *udata) { \
+ int eq = 0; \
+ if (type_info == NULL || type_info->equal == NULL) { return 0; } \
+ eq = type_info->equal(expd, got, udata); \
+ if (!eq) { \
+ if (type_info->print != NULL) { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\nExpected: "); \
+ (void)type_info->print(expd, udata); \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n Got: "); \
+ (void)type_info->print(got, udata); \
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n"); \
+ } \
+ } \
+ return eq; \
+} \
+ \
+static void greatest_usage(const char *name) { \
+ GREATEST_FPRINTF(GREATEST_STDOUT, \
+ "Usage: %s [-hlfavex] [-s SUITE] [-t TEST] [-x EXCLUDE]\n" \
+ " -h, --help print this Help\n" \
+ " -l List suites and tests, then exit (dry run)\n" \
+ " -f Stop runner after first failure\n" \
+ " -a Abort on first failure (implies -f)\n" \
+ " -v Verbose output\n" \
+ " -s SUITE only run suites containing substring SUITE\n" \
+ " -t TEST only run tests containing substring TEST\n" \
+ " -e only run exact name match for -s or -t\n" \
+ " -x EXCLUDE exclude tests containing substring EXCLUDE\n", \
+ name); \
+} \
+ \
+static void greatest_parse_options(int argc, char **argv) { \
+ int i = 0; \
+ for (i = 1; i < argc; i++) { \
+ if (argv[i][0] == '-') { \
+ char f = argv[i][1]; \
+ if ((f == 's' || f == 't' || f == 'x') && argc <= i + 1) { \
+ greatest_usage(argv[0]); exit(EXIT_FAILURE); \
+ } \
+ switch (f) { \
+ case 's': /* suite name filter */ \
+ greatest_set_suite_filter(argv[i + 1]); i++; break; \
+ case 't': /* test name filter */ \
+ greatest_set_test_filter(argv[i + 1]); i++; break; \
+ case 'x': /* test name exclusion */ \
+ greatest_set_test_exclude(argv[i + 1]); i++; break; \
+ case 'e': /* exact name match */ \
+ greatest_set_exact_name_match(); break; \
+ case 'f': /* first fail flag */ \
+ greatest_stop_at_first_fail(); break; \
+ case 'a': /* abort() on fail flag */ \
+ greatest_abort_on_fail(); break; \
+ case 'l': /* list only (dry run) */ \
+ greatest_list_only(); break; \
+ case 'v': /* first fail flag */ \
+ greatest_info.verbosity++; break; \
+ case 'h': /* help */ \
+ greatest_usage(argv[0]); exit(EXIT_SUCCESS); \
+ default: \
+ case '-': \
+ if (0 == strncmp("--help", argv[i], 6)) { \
+ greatest_usage(argv[0]); exit(EXIT_SUCCESS); \
+ } else if (0 == strcmp("--", argv[i])) { \
+ return; /* ignore following arguments */ \
+ } \
+ GREATEST_FPRINTF(GREATEST_STDOUT, \
+ "Unknown argument '%s'\n", argv[i]); \
+ greatest_usage(argv[0]); \
+ exit(EXIT_FAILURE); \
+ } \
+ } \
+ } \
+} \
+ \
+int greatest_all_passed(void) { return (greatest_info.failed == 0); } \
+ \
+void greatest_set_test_filter(const char *filter) { \
+ greatest_info.test_filter = filter; \
+} \
+ \
+void greatest_set_test_exclude(const char *filter) { \
+ greatest_info.test_exclude = filter; \
+} \
+ \
+void greatest_set_suite_filter(const char *filter) { \
+ greatest_info.suite_filter = filter; \
+} \
+ \
+void greatest_set_exact_name_match(void) { \
+ greatest_info.exact_name_match = 1; \
+} \
+ \
+void greatest_stop_at_first_fail(void) { \
+ greatest_set_flag(GREATEST_FLAG_FIRST_FAIL); \
+} \
+ \
+void greatest_abort_on_fail(void) { \
+ greatest_set_flag(GREATEST_FLAG_ABORT_ON_FAIL); \
+} \
+ \
+void greatest_list_only(void) { \
+ greatest_set_flag(GREATEST_FLAG_LIST_ONLY); \
+} \
+ \
+void greatest_get_report(struct greatest_report_t *report) { \
+ if (report) { \
+ report->passed = greatest_info.passed; \
+ report->failed = greatest_info.failed; \
+ report->skipped = greatest_info.skipped; \
+ report->assertions = greatest_info.assertions; \
+ } \
+} \
+ \
+unsigned int greatest_get_verbosity(void) { \
+ return greatest_info.verbosity; \
+} \
+ \
+void greatest_set_verbosity(unsigned int verbosity) { \
+ greatest_info.verbosity = (unsigned char)verbosity; \
+} \
+ \
+void greatest_set_flag(greatest_flag_t flag) { \
+ greatest_info.flags = (unsigned char)(greatest_info.flags | flag); \
+} \
+ \
+void greatest_set_test_suffix(const char *suffix) { \
+ greatest_info.name_suffix = suffix; \
+} \
+ \
+void GREATEST_SET_SETUP_CB(greatest_setup_cb *cb, void *udata) { \
+ greatest_info.setup = cb; \
+ greatest_info.setup_udata = udata; \
+} \
+ \
+void GREATEST_SET_TEARDOWN_CB(greatest_teardown_cb *cb, void *udata) { \
+ greatest_info.teardown = cb; \
+ greatest_info.teardown_udata = udata; \
+} \
+ \
+static int greatest_string_equal_cb(const void *expd, const void *got, \
+ void *udata) { \
+ size_t *size = (size_t *)udata; \
+ return (size != NULL \
+ ? (0 == strncmp((const char *)expd, (const char *)got, *size)) \
+ : (0 == strcmp((const char *)expd, (const char *)got))); \
+} \
+ \
+static int greatest_string_printf_cb(const void *t, void *udata) { \
+ (void)udata; /* note: does not check \0 termination. */ \
+ return GREATEST_FPRINTF(GREATEST_STDOUT, "%s", (const char *)t); \
+} \
+ \
+greatest_type_info greatest_type_info_string = { \
+ greatest_string_equal_cb, greatest_string_printf_cb, \
+}; \
+ \
+static int greatest_memory_equal_cb(const void *expd, const void *got, \
+ void *udata) { \
+ greatest_memory_cmp_env *env = (greatest_memory_cmp_env *)udata; \
+ return (0 == memcmp(expd, got, env->size)); \
+} \
+ \
+/* Hexdump raw memory, with differences highlighted */ \
+static int greatest_memory_printf_cb(const void *t, void *udata) { \
+ greatest_memory_cmp_env *env = (greatest_memory_cmp_env *)udata; \
+ const unsigned char *buf = (const unsigned char *)t; \
+ unsigned char diff_mark = ' '; \
+ FILE *out = GREATEST_STDOUT; \
+ size_t i, line_i, line_len = 0; \
+ int len = 0; /* format hexdump with differences highlighted */ \
+ for (i = 0; i < env->size; i+= line_len) { \
+ diff_mark = ' '; \
+ line_len = env->size - i; \
+ if (line_len > 16) { line_len = 16; } \
+ for (line_i = i; line_i < i + line_len; line_i++) { \
+ if (env->exp[line_i] != env->got[line_i]) diff_mark = 'X'; \
+ } \
+ len += GREATEST_FPRINTF(out, "\n%04x %c ", \
+ (unsigned int)i, diff_mark); \
+ for (line_i = i; line_i < i + line_len; line_i++) { \
+ int m = env->exp[line_i] == env->got[line_i]; /* match? */ \
+ len += GREATEST_FPRINTF(out, "%02x%c", \
+ buf[line_i], m ? ' ' : '<'); \
+ } \
+ for (line_i = 0; line_i < 16 - line_len; line_i++) { \
+ len += GREATEST_FPRINTF(out, " "); \
+ } \
+ GREATEST_FPRINTF(out, " "); \
+ for (line_i = i; line_i < i + line_len; line_i++) { \
+ unsigned char c = buf[line_i]; \
+ len += GREATEST_FPRINTF(out, "%c", isprint(c) ? c : '.'); \
+ } \
+ } \
+ len += GREATEST_FPRINTF(out, "\n"); \
+ return len; \
+} \
+ \
+void greatest_prng_init_first_pass(int id) { \
+ greatest_info.prng[id].random_order = 1; \
+ greatest_info.prng[id].count_run = 0; \
+} \
+ \
+int greatest_prng_init_second_pass(int id, unsigned long seed) { \
+ struct greatest_prng *p = &greatest_info.prng[id]; \
+ if (p->count == 0) { return 0; } \
+ p->count_ceil = p->count; \
+ for (p->m = 1; p->m < p->count; p->m <<= 1) {} \
+ p->state = seed & 0x1fffffff; /* only use lower 29 bits */ \
+ p->a = 4LU * p->state; /* to avoid overflow when */ \
+ p->a = (p->a ? p->a : 4) | 1; /* multiplied by 4 */ \
+ p->c = 2147483647; /* and so p->c ((2 ** 31) - 1) is */ \
+ p->initialized = 1; /* always relatively prime to p->a. */ \
+ fprintf(stderr, "init_second_pass: a %lu, c %lu, state %lu\n", \
+ p->a, p->c, p->state); \
+ return 1; \
+} \
+ \
+/* Step the pseudorandom number generator until its state reaches \
+ * another test ID between 0 and the test count. \
+ * This use a linear congruential pseudorandom number generator, \
+ * with the power-of-two ceiling of the test count as the modulus, the \
+ * masked seed as the multiplier, and a prime as the increment. For \
+ * each generated value < the test count, run the corresponding test. \
+ * This will visit all IDs 0 <= X < mod once before repeating, \
+ * with a starting position chosen based on the initial seed. \
+ * For details, see: Knuth, The Art of Computer Programming \
+ * Volume. 2, section 3.2.1. */ \
+void greatest_prng_step(int id) { \
+ struct greatest_prng *p = &greatest_info.prng[id]; \
+ do { \
+ p->state = ((p->a * p->state) + p->c) & (p->m - 1); \
+ } while (p->state >= p->count_ceil); \
+} \
+ \
+void GREATEST_INIT(void) { \
+ /* Suppress unused function warning if features aren't used */ \
+ (void)greatest_run_suite; \
+ (void)greatest_parse_options; \
+ (void)greatest_prng_step; \
+ (void)greatest_prng_init_first_pass; \
+ (void)greatest_prng_init_second_pass; \
+ (void)greatest_set_test_suffix; \
+ \
+ memset(&greatest_info, 0, sizeof(greatest_info)); \
+ greatest_info.width = GREATEST_DEFAULT_WIDTH; \
+ GREATEST_SET_TIME(greatest_info.begin); \
+} \
+ \
+/* Report passes, failures, skipped tests, the number of \
+ * assertions, and the overall run time. */ \
+void GREATEST_PRINT_REPORT(void) { \
+ if (!GREATEST_LIST_ONLY()) { \
+ update_counts_and_reset_suite(); \
+ GREATEST_SET_TIME(greatest_info.end); \
+ GREATEST_FPRINTF(GREATEST_STDOUT, \
+ "\nTotal: %u test%s", \
+ greatest_info.tests_run, \
+ greatest_info.tests_run == 1 ? "" : "s"); \
+ GREATEST_CLOCK_DIFF(greatest_info.begin, \
+ greatest_info.end); \
+ GREATEST_FPRINTF(GREATEST_STDOUT, ", %u assertion%s\n", \
+ greatest_info.assertions, \
+ greatest_info.assertions == 1 ? "" : "s"); \
+ GREATEST_FPRINTF(GREATEST_STDOUT, \
+ "Pass: %u, fail: %u, skip: %u.\n", \
+ greatest_info.passed, \
+ greatest_info.failed, greatest_info.skipped); \
+ } \
+} \
+ \
+greatest_type_info greatest_type_info_memory = { \
+ greatest_memory_equal_cb, greatest_memory_printf_cb, \
+}; \
+ \
+greatest_run_info greatest_info
+
+/* Handle command-line arguments, etc. */
+#define GREATEST_MAIN_BEGIN() \
+ do { \
+ GREATEST_INIT(); \
+ greatest_parse_options(argc, argv); \
+ } while (0)
+
+/* Report results, exit with exit status based on results. */
+#define GREATEST_MAIN_END() \
+ do { \
+ GREATEST_PRINT_REPORT(); \
+ return (greatest_all_passed() ? EXIT_SUCCESS : EXIT_FAILURE); \
+ } while (0)
+
+/* Make abbreviations without the GREATEST_ prefix for the
+ * most commonly used symbols. */
+#if GREATEST_USE_ABBREVS
+#define TEST GREATEST_TEST
+#define SUITE GREATEST_SUITE
+#define SUITE_EXTERN GREATEST_SUITE_EXTERN
+#define RUN_TEST GREATEST_RUN_TEST
+#define RUN_TEST1 GREATEST_RUN_TEST1
+#define RUN_SUITE GREATEST_RUN_SUITE
+#define IGNORE_TEST GREATEST_IGNORE_TEST
+#define ASSERT GREATEST_ASSERT
+#define ASSERTm GREATEST_ASSERTm
+#define ASSERT_FALSE GREATEST_ASSERT_FALSE
+#define ASSERT_EQ GREATEST_ASSERT_EQ
+#define ASSERT_NEQ GREATEST_ASSERT_NEQ
+#define ASSERT_GT GREATEST_ASSERT_GT
+#define ASSERT_GTE GREATEST_ASSERT_GTE
+#define ASSERT_LT GREATEST_ASSERT_LT
+#define ASSERT_LTE GREATEST_ASSERT_LTE
+#define ASSERT_EQ_FMT GREATEST_ASSERT_EQ_FMT
+#define ASSERT_IN_RANGE GREATEST_ASSERT_IN_RANGE
+#define ASSERT_EQUAL_T GREATEST_ASSERT_EQUAL_T
+#define ASSERT_STR_EQ GREATEST_ASSERT_STR_EQ
+#define ASSERT_STRN_EQ GREATEST_ASSERT_STRN_EQ
+#define ASSERT_MEM_EQ GREATEST_ASSERT_MEM_EQ
+#define ASSERT_ENUM_EQ GREATEST_ASSERT_ENUM_EQ
+#define ASSERT_FALSEm GREATEST_ASSERT_FALSEm
+#define ASSERT_EQm GREATEST_ASSERT_EQm
+#define ASSERT_NEQm GREATEST_ASSERT_NEQm
+#define ASSERT_GTm GREATEST_ASSERT_GTm
+#define ASSERT_GTEm GREATEST_ASSERT_GTEm
+#define ASSERT_LTm GREATEST_ASSERT_LTm
+#define ASSERT_LTEm GREATEST_ASSERT_LTEm
+#define ASSERT_EQ_FMTm GREATEST_ASSERT_EQ_FMTm
+#define ASSERT_IN_RANGEm GREATEST_ASSERT_IN_RANGEm
+#define ASSERT_EQUAL_Tm GREATEST_ASSERT_EQUAL_Tm
+#define ASSERT_STR_EQm GREATEST_ASSERT_STR_EQm
+#define ASSERT_STRN_EQm GREATEST_ASSERT_STRN_EQm
+#define ASSERT_MEM_EQm GREATEST_ASSERT_MEM_EQm
+#define ASSERT_ENUM_EQm GREATEST_ASSERT_ENUM_EQm
+#define PASS GREATEST_PASS
+#define FAIL GREATEST_FAIL
+#define SKIP GREATEST_SKIP
+#define PASSm GREATEST_PASSm
+#define FAILm GREATEST_FAILm
+#define SKIPm GREATEST_SKIPm
+#define SET_SETUP GREATEST_SET_SETUP_CB
+#define SET_TEARDOWN GREATEST_SET_TEARDOWN_CB
+#define CHECK_CALL GREATEST_CHECK_CALL
+#define SHUFFLE_TESTS GREATEST_SHUFFLE_TESTS
+#define SHUFFLE_SUITES GREATEST_SHUFFLE_SUITES
+
+#ifdef GREATEST_VA_ARGS
+#define RUN_TESTp GREATEST_RUN_TESTp
+#endif
+
+#if GREATEST_USE_LONGJMP
+#define ASSERT_OR_LONGJMP GREATEST_ASSERT_OR_LONGJMP
+#define ASSERT_OR_LONGJMPm GREATEST_ASSERT_OR_LONGJMPm
+#define FAIL_WITH_LONGJMP GREATEST_FAIL_WITH_LONGJMP
+#define FAIL_WITH_LONGJMPm GREATEST_FAIL_WITH_LONGJMPm
+#endif
+
+#endif /* USE_ABBREVS */
+
+#if defined(__cplusplus) && !defined(GREATEST_NO_EXTERN_CPLUSPLUS)
+}
+#endif
+
+#endif
diff --git a/libs/greatest/package.json b/libs/greatest/package.json
new file mode 100644
index 0000000..944ba3f
--- /dev/null
+++ b/libs/greatest/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "greatest",
+ "version": "v1.5.0",
+ "repo": "silentbicycle/greatest",
+ "src": ["greatest.h"],
+ "description": "A C testing library in 1 file. No dependencies, no dynamic allocation.",
+ "license": "ISC",
+ "keywords": ["test", "unit", "testing"]
+}