Cgreen testing framework in C packaged by donaldsebleung, for solving Codewars Kata locally and more
This is an unofficial build not endorsed or supported by upstream in any way.
Current supported architectures are:
amd64
arm64
riscv64
Pull the image:
$ docker pull docker.io/donaldsebleung/cgreen
You can also pull the image for an architecture other than the native one for your device (default), if you are using Docker Desktop, or have otherwise enabled QEMU user-mode emulation on the container host. For example, to pull the image for riscv64
architecture:
$ docker pull --platform linux/riscv64 docker.io/donaldsebleung/cgreen
Place the following files in your working directory:
preloaded.h
: interfacesolution.c
: implementationsolution_tests.c
: Cgreen unit tests
For solution_tests.c
, you should not define a main()
function at all - instead, you need to define a function with signature TestSuite *solution_tests()
, e.g.
#include <cgreen/cgreen.h>
Describe(Trivial);
BeforeEach(Trivial) {}
AfterEach(Trivial) {}
Ensure(Trivial, should_work_for_a_trivial_test) {
assert_that(1);
}
TestSuite *solution_tests() {
TestSuite *suite = create_test_suite();
add_test_with_context(suite, Trivial, should_work_for_a_trivial_test);
return suite;
}
Then, to compile and execute the code:
$ ./run.sh
By default, the script assumes you have Docker installed. If you have another container engine such as Podman installed, specify it through CONTAINER_ENGINE
:
$ CONTAINER_ENGINE=podman ./run.sh
To specify a particular architecture (default: amd64
), set the ARCH
variable. For example, to compile and execute the code on riscv64
architecture:
$ ARCH=riscv64 ./run.sh
If your implementation is in assembly instead of C, replace solution.c
with an equivalent assembly program solution.s
, and pass the --with-asm
flag to run.sh
:
$ ./run.sh --with-asm