Skip to content

Commit e7f04f6

Browse files
pks-tgitster
authored andcommitted
t/unit-tests: update clar to fcbed04
Update clar to fcbed04 (Merge pull request #123 from pks-gitlab/pks-sandbox-ubsan, 2025-09-10). The most significant changes since the last version include: - Fixed platform support for HP-UX. - Fixes for how clar handles the `-q` flag. - A couple of leak fixes for reported clar errors. - A new `cl_invoke()` function that retains line information. - New infrastructure to create temporary directories. - Improved printing of error messages so that all lines are now properly indented. - Proper selftests for the clar. Most of these changes are somewhat irrelevant to us, but neither do we have to adjust to any of these changes, either. What _is_ interesting to us though is especially the fixed support for HP-UX, and eventually we may also want to use `cl_invoke()`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c44beea commit e7f04f6

32 files changed

+1311
-238
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ jobs:
1313
platform:
1414
- os: ubuntu-latest
1515
generator: Unix Makefiles
16+
- os: ubuntu-latest
17+
generator: Unix Makefiles
18+
env:
19+
CC: "clang"
20+
CFLAGS: "-fsanitize=leak"
1621
- os: macos-latest
1722
generator: Unix Makefiles
1823
- os: windows-latest
@@ -21,15 +26,26 @@ jobs:
2126
generator: MSYS Makefiles
2227
- os: windows-latest
2328
generator: MinGW Makefiles
29+
fail-fast: false
2430

2531
runs-on: ${{ matrix.platform.os }}
2632

33+
env:
34+
CC: ${{matrix.platform.env.CC}}
35+
CFLAGS: ${{matrix.platform.env.CFLAGS}}
36+
2737
steps:
2838
- name: Check out
2939
uses: actions/checkout@v2
3040
- name: Build
41+
shell: bash
3142
run: |
3243
mkdir build
3344
cd build
3445
cmake .. -G "${{matrix.platform.generator}}"
35-
cmake --build .
46+
cmake --build . --verbose
47+
- name: Test
48+
shell: bash
49+
run: |
50+
cd build
51+
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)