Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use argument as test data directory #1373

Merged
merged 3 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ endif
test: test/test clean-coverage-run
# Make sure an error code is returned when the test fails
/usr/bin/env bash -c 'set -euo pipefail;\
./test/test -v | ./test/greenest.awk '
./test/test ./test | ./test/greenest.awk '

test-valgrind: test/test
${VALGRIND} \
Expand All @@ -104,7 +104,7 @@ test-valgrind: test/test
--errors-for-leak-kinds=definite \
--num-callers=40 \
--error-exitcode=123 \
./test/test -v
./test/test ./test

test-coverage: CFLAGS += -fprofile-arcs -ftest-coverage -O0
test-coverage: test
Expand Down
12 changes: 7 additions & 5 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ SUITE_EXTERN(suite_input);
GREATEST_MAIN_DEFS();

int main(int argc, char *argv[]) {
char *prog = realpath(argv[0], NULL);
if (!prog) {
if (argc != 2) {
fprintf(stderr, "Usage: %s testdatadir", argv[0]);
exit(1);
}

base = realpath(argv[1], NULL);
if (!base) {
fprintf(stderr, "Cannot determine actual path of test executable: %s\n", strerror(errno));
exit(1);
}
base = dirname(prog);

/* By default do not print out warning messages, when executing tests.
* But allow, if DUNST_TEST_LOG=1 is set in environment. */
Expand Down Expand Up @@ -71,9 +75,7 @@ int main(int argc, char *argv[]) {
RUN_SUITE(suite_rules);
RUN_SUITE(suite_input);

base = NULL;
g_strfreev(configs);
free(prog);

// this returns the error code
GREATEST_MAIN_END();
Expand Down