Skip to content

Commit 347af01

Browse files
committed
Merge branch 'ps/clar-updates'
Import a newer version of the clar unit testing framework. * ps/clar-updates: t/unit-tests: update to 10e96bc t/unit-tests: update clar to fcbed04
2 parents bb69721 + 93dbb6b commit 347af01

34 files changed

+1415
-258
lines changed

t/unit-tests/clar/.github/workflows/ci.yml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,56 @@ jobs:
1313
platform:
1414
- os: ubuntu-latest
1515
generator: Unix Makefiles
16+
env:
17+
CFLAGS: "-Werror -Wall -Wextra"
18+
- os: ubuntu-latest
19+
generator: Unix Makefiles
20+
env:
21+
CC: "clang"
22+
CFLAGS: "-Werror -Wall -Wextra -fsanitize=leak"
23+
- os: ubuntu-latest
24+
generator: Unix Makefiles
25+
image: i386/debian:latest
26+
env:
27+
CFLAGS: "-Werror -Wall -Wextra"
1628
- os: macos-latest
1729
generator: Unix Makefiles
30+
env:
31+
CFLAGS: "-Werror -Wall -Wextra"
1832
- os: windows-latest
1933
generator: Visual Studio 17 2022
2034
- os: windows-latest
2135
generator: MSYS Makefiles
36+
env:
37+
CFLAGS: "-Werror -Wall -Wextra"
2238
- os: windows-latest
2339
generator: MinGW Makefiles
40+
env:
41+
CFLAGS: "-Werror -Wall -Wextra"
42+
fail-fast: false
2443

2544
runs-on: ${{ matrix.platform.os }}
45+
container: ${{matrix.platform.image}}
46+
47+
env:
48+
CC: ${{matrix.platform.env.CC}}
49+
CFLAGS: ${{matrix.platform.env.CFLAGS}}
2650

2751
steps:
52+
- name: Prepare 32 bit container image
53+
if: matrix.platform.image == 'i386/debian:latest'
54+
run: apt -q update && apt -q -y install cmake gcc libc6-amd64 lib64stdc++6 make python3
2855
- name: Check out
29-
uses: actions/checkout@v2
56+
uses: actions/checkout@v4
3057
- name: Build
58+
shell: bash
3159
run: |
3260
mkdir build
3361
cd build
3462
cmake .. -G "${{matrix.platform.generator}}"
35-
cmake --build .
63+
cmake --build . --verbose
64+
- name: Test
65+
shell: bash
66+
run: |
67+
cd build
68+
CTEST_OUTPUT_ON_FAILURE=1 ctest --build-config Debug

t/unit-tests/clar/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
include(CheckFunctionExists)
2+
13
cmake_minimum_required(VERSION 3.16..3.29)
24

35
project(clar LANGUAGES C)
46

5-
option(BUILD_TESTS "Build test executable" ON)
7+
option(BUILD_EXAMPLE "Build the example." ON)
8+
9+
check_function_exists(realpath CLAR_HAS_REALPATH)
10+
if(CLAR_HAS_REALPATH)
11+
add_compile_definitions(-DCLAR_HAS_REALPATH)
12+
endif()
613

714
add_library(clar INTERFACE)
815
target_sources(clar INTERFACE
@@ -25,4 +32,8 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
2532
if(BUILD_TESTING)
2633
add_subdirectory(test)
2734
endif()
35+
36+
if(BUILD_EXAMPLE)
37+
add_subdirectory(example)
38+
endif()
2839
endif()

t/unit-tests/clar/README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ Can you count to funk?
2626
~~~~ sh
2727
$ mkdir tests
2828
$ cp -r $CLAR_ROOT/clar* tests
29-
$ cp $CLAR_ROOT/test/clar_test.h tests
30-
$ cp $CLAR_ROOT/test/main.c.sample tests/main.c
29+
$ cp $CLAR_ROOT/example/*.c tests
3130
~~~~
3231

3332
- **One: Write some tests**
@@ -147,7 +146,7 @@ To use Clar:
147146

148147
1. copy the Clar boilerplate to your test directory
149148
2. copy (and probably modify) the sample `main.c` (from
150-
`$CLAR_PATH/test/main.c.sample`)
149+
`$CLAR_PATH/example/main.c`)
151150
3. run the Clar mixer (a.k.a. `generate.py`) to scan your test directory and
152151
write out the test suite metadata.
153152
4. compile your test files and the Clar boilerplate into a single test
@@ -159,7 +158,7 @@ The Clar boilerplate gives you a set of useful test assertions and features
159158
the `clar.c` and `clar.h` files, plus the code in the `clar/` subdirectory.
160159
You should not need to edit these files.
161160

162-
The sample `main.c` (i.e. `$CLAR_PATH/test/main.c.sample`) file invokes
161+
The sample `main.c` (i.e. `$CLAR_PATH/example/main.c`) file invokes
163162
`clar_test(argc, argv)` to run the tests. Usually, you will edit this file
164163
to perform any framework specific initialization and teardown that you need.
165164

@@ -251,11 +250,16 @@ suite.
251250

252251
- `cl_fixture(const char *)`: Gets the full path to a fixture file.
253252

254-
Please do note that these methods are *always* available whilst running a
255-
test, even when calling auxiliary/static functions inside the same file.
253+
### Auxiliary / helper functions
256254

257-
It's strongly encouraged to perform test assertions in auxiliary methods,
258-
instead of returning error values. This is considered good Clar style.
255+
The clar API is always available while running a test, even when calling
256+
"auxiliary" (helper) functions.
257+
258+
You're encouraged to perform test assertions in those auxiliary
259+
methods, instead of returning error values. This is considered good
260+
Clar style. _However_, when you do this, you need to call `cl_invoke`
261+
to preserve the current state; this ensures that failures are reported
262+
as coming from the actual test, instead of the auxiliary method.
259263
260264
Style Example:
261265
@@ -310,20 +314,19 @@ static void check_string(const char *str)
310314
311315
void test_example__a_test_with_auxiliary_methods(void)
312316
{
313-
check_string("foo");
314-
check_string("bar");
317+
cl_invoke(check_string("foo"));
318+
cl_invoke(check_string("bar"));
315319
}
316320
~~~~
317321
318322
About Clar
319323
==========
320324
321-
Clar has been written from scratch by [Vicent Martí](https://github.com/vmg),
322-
to replace the old testing framework in [libgit2][libgit2].
323-
324-
Do you know what languages are *in* on the SF startup scene? Node.js *and*
325-
Latin. Follow [@vmg](https://www.twitter.com/vmg) on Twitter to
326-
receive more lessons on word etymology. You can be hip too.
327-
325+
Clar was originally written by [Vicent Martí](https://github.com/vmg),
326+
to replace the old testing framework in [libgit2][libgit2]. It is
327+
currently maintained by [Edward Thomson](https://github.com/ethomson),
328+
and used by the [libgit2][libgit2] and [git][git] projects, amongst
329+
others.
328330
329331
[libgit2]: https://github.com/libgit2/libgit2
332+
[git]: https://github.com/git/git

0 commit comments

Comments
 (0)