diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-12-10 03:37:47 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-12-10 03:37:47 +0300 |
commit | 712177ed04c3c33bfe6075b9cc2d4d65e2cc04c2 (patch) | |
tree | 8df51ee4592da83321ef0d6da21395ca262a62e8 /t | |
parent | 8bf6fbd00dc74c5c83ff5a20ef9293a9d77845a8 (diff) | |
parent | 694e89baeb824a173b655507b7b62174d2d15688 (diff) |
Merge branch 'js/doc-unit-tests-with-cmake'
Update the base topic to work with CMake builds.
* js/doc-unit-tests-with-cmake:
cmake: handle also unit tests
cmake: use test names instead of full paths
cmake: fix typo in variable name
artifacts-tar: when including `.dll` files, don't forget the unit-tests
unit-tests: do show relative file paths
unit-tests: do not mistake `.pdb` files for being executable
cmake: also build unit tests
Diffstat (limited to 't')
-rw-r--r-- | t/Makefile | 2 | ||||
-rw-r--r-- | t/unit-tests/test-lib.c | 52 |
2 files changed, 49 insertions, 5 deletions
diff --git a/t/Makefile b/t/Makefile index 75d9330437..225aaf78ed 100644 --- a/t/Makefile +++ b/t/Makefile @@ -42,7 +42,7 @@ TPERF = $(sort $(wildcard perf/p[0-9][0-9][0-9][0-9]-*.sh)) TINTEROP = $(sort $(wildcard interop/i[0-9][0-9][0-9][0-9]-*.sh)) CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.test))) CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl -UNIT_TESTS = $(sort $(filter-out unit-tests/bin/t-basic%,$(wildcard unit-tests/bin/t-*))) +UNIT_TESTS = $(sort $(filter-out %.pdb unit-tests/bin/t-basic%,$(wildcard unit-tests/bin/t-*))) # `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`) # checks all tests in all scripts via a single invocation, so tell individual diff --git a/t/unit-tests/test-lib.c b/t/unit-tests/test-lib.c index a2cc21c706..7bf9dfdb95 100644 --- a/t/unit-tests/test-lib.c +++ b/t/unit-tests/test-lib.c @@ -21,6 +21,46 @@ static struct { .result = RESULT_NONE, }; +#ifndef _MSC_VER +#define make_relative(location) location +#else +/* + * Visual C interpolates the absolute Windows path for `__FILE__`, + * but we want to see relative paths, as verified by t0080. + */ +#include "dir.h" + +static const char *make_relative(const char *location) +{ + static char prefix[] = __FILE__, buf[PATH_MAX], *p; + static size_t prefix_len; + + if (!prefix_len) { + size_t len = strlen(prefix); + const char *needle = "\\t\\unit-tests\\test-lib.c"; + size_t needle_len = strlen(needle); + + if (len < needle_len || strcmp(needle, prefix + len - needle_len)) + die("unexpected suffix of '%s'", prefix); + + /* let it end in a directory separator */ + prefix_len = len - needle_len + 1; + } + + /* Does it not start with the expected prefix? */ + if (fspathncmp(location, prefix, prefix_len)) + return location; + + strlcpy(buf, location + prefix_len, sizeof(buf)); + /* convert backslashes to forward slashes */ + for (p = buf; *p; p++) + if (*p == '\\') + *p = '/'; + + return buf; +} +#endif + static void msg_with_prefix(const char *prefix, const char *format, va_list ap) { fflush(stderr); @@ -147,7 +187,8 @@ int test__run_end(int was_run UNUSED, const char *location, const char *format, break; case RESULT_NONE: - test_msg("BUG: test has no checks at %s", location); + test_msg("BUG: test has no checks at %s", + make_relative(location)); printf("not ok %d", ctx.count); print_description(format, ap); ctx.result = RESULT_FAILURE; @@ -193,14 +234,16 @@ int test_assert(const char *location, const char *check, int ok) assert(ctx.running); if (ctx.result == RESULT_SKIP) { - test_msg("skipping check '%s' at %s", check, location); + test_msg("skipping check '%s' at %s", check, + make_relative(location)); return 1; } if (!ctx.todo) { if (ok) { test_pass(); } else { - test_msg("check \"%s\" failed at %s", check, location); + test_msg("check \"%s\" failed at %s", check, + make_relative(location)); test_fail(); } } @@ -225,7 +268,8 @@ int test__todo_end(const char *location, const char *check, int res) if (ctx.result == RESULT_SKIP) return 1; if (res) { - test_msg("todo check '%s' succeeded at %s", check, location); + test_msg("todo check '%s' succeeded at %s", check, + make_relative(location)); test_fail(); } else { test_todo(); |