From 6e3734f74fbad22a09112aa0546f0375b6d4eedc Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Tue, 28 Mar 2023 22:30:50 -0700 Subject: [PATCH] tests: fix unit tests to run with a dynamic log directory Ref: #10818 --- tests/data/test1304 | 3 +++ tests/data/test1308 | 3 +++ tests/data/test1660 | 6 +++--- tests/data/test3200 | 3 +++ tests/unit/README.md | 2 +- tests/unit/unit1304.c | 30 +++++++++--------------------- tests/unit/unit1308.c | 2 +- tests/unit/unit1660.c | 6 ++++-- tests/unit/unit3200.c | 6 ++---- 9 files changed, 29 insertions(+), 32 deletions(-) diff --git a/tests/data/test1304 b/tests/data/test1304 index 438e5886c7..afc9aed1e9 100644 --- a/tests/data/test1304 +++ b/tests/data/test1304 @@ -18,6 +18,9 @@ unittest netrc parsing unit tests + +%LOGDIR/netrc%TESTNUMBER + machine example.com login admin password passwd machine curl.example.com login none password none diff --git a/tests/data/test1308 b/tests/data/test1308 index 9bd5c056d4..7ec1b98840 100644 --- a/tests/data/test1308 +++ b/tests/data/test1308 @@ -21,6 +21,9 @@ Mime formpost unit tests + +%LOGDIR/test-%TESTNUMBER + Piece of the file that is to uploaded as a formpost diff --git a/tests/data/test1660 b/tests/data/test1660 index e21fec4752..f86126d19c 100644 --- a/tests/data/test1660 +++ b/tests/data/test1660 @@ -15,7 +15,7 @@ unittest HSTS - + # Your HSTS cache. https://curl.se/docs/hsts.html # This file was generated by libcurl! Edit at your own risk. .readfrom.example "20211001 04:47:41" @@ -31,7 +31,7 @@ CURL_TIME=1548369261 HSTS -- +%LOGDIR/hsts%TESTNUMBER @@ -72,7 +72,7 @@ expire.example [expire.example]: 1548369268 'expire.example' is not HSTS 'expire.example' is not HSTS - + # Your HSTS cache. https://curl.se/docs/hsts.html # This file was generated by libcurl! Edit at your own risk. .new.example "unlimited" diff --git a/tests/data/test3200 b/tests/data/test3200 index 0904cd6d6e..a2f9074019 100644 --- a/tests/data/test3200 +++ b/tests/data/test3200 @@ -18,5 +18,8 @@ unittest curl_get_line unit tests + +%LOGDIR/curl_get_line%TESTNUMBER + diff --git a/tests/unit/README.md b/tests/unit/README.md index cb3420c64f..f111190050 100644 --- a/tests/unit/README.md +++ b/tests/unit/README.md @@ -26,7 +26,7 @@ can `cd tests` and `make` and then invoke individual unit tests with ## Debug Unit Tests If a specific test fails you will get told. The test case then has output left -in the log/ subdirectory, but most importantly you can re-run the test again +in the %LOGDIR subdirectory, but most importantly you can re-run the test again using gdb by doing `./runtests.pl -g NNNN`. That is, add a `-g` to make it start up gdb and run the same case using that. diff --git a/tests/unit/unit1304.c b/tests/unit/unit1304.c index 2e7e97a760..cb7f7bb28a 100644 --- a/tests/unit/unit1304.c +++ b/tests/unit/unit1304.c @@ -27,7 +27,6 @@ static char *login; static char *password; -static char filename[64]; static CURLcode unit_setup(void) { @@ -50,14 +49,10 @@ static void unit_stop(void) UNITTEST_START int result; - static const char * const filename1 = "log/netrc1304"; - memcpy(filename, filename1, strlen(filename1)); - /* * Test a non existent host in our netrc file. */ - result = Curl_parsenetrc("test.example.com", &login, &password, - filename); + result = Curl_parsenetrc("test.example.com", &login, &password, arg); fail_unless(result == 1, "Host not found should return 1"); abort_unless(password != NULL, "returned NULL!"); fail_unless(password[0] == 0, "password should not have been changed"); @@ -70,8 +65,7 @@ UNITTEST_START free(login); login = strdup("me"); abort_unless(login != NULL, "returned NULL!"); - result = Curl_parsenetrc("example.com", &login, &password, - filename); + result = Curl_parsenetrc("example.com", &login, &password, arg); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(password[0] == 0, "password should not have been changed"); @@ -85,8 +79,7 @@ UNITTEST_START free(login); login = strdup("me"); abort_unless(login != NULL, "returned NULL!"); - result = Curl_parsenetrc("test.example.com", &login, &password, - filename); + result = Curl_parsenetrc("test.example.com", &login, &password, arg); fail_unless(result == 1, "Host not found should return 1"); abort_unless(password != NULL, "returned NULL!"); fail_unless(password[0] == 0, "password should not have been changed"); @@ -101,8 +94,7 @@ UNITTEST_START free(login); login = strdup("admi"); abort_unless(login != NULL, "returned NULL!"); - result = Curl_parsenetrc("example.com", &login, &password, - filename); + result = Curl_parsenetrc("example.com", &login, &password, arg); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(password[0] == 0, "password should not have been changed"); @@ -117,8 +109,7 @@ UNITTEST_START free(login); login = strdup("adminn"); abort_unless(login != NULL, "returned NULL!"); - result = Curl_parsenetrc("example.com", &login, &password, - filename); + result = Curl_parsenetrc("example.com", &login, &password, arg); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(password[0] == 0, "password should not have been changed"); @@ -133,8 +124,7 @@ UNITTEST_START free(login); login = strdup(""); abort_unless(login != NULL, "returned NULL!"); - result = Curl_parsenetrc("example.com", &login, &password, - filename); + result = Curl_parsenetrc("example.com", &login, &password, arg); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(strncmp(password, "passwd", 6) == 0, @@ -149,7 +139,7 @@ UNITTEST_START free(password); password = strdup(""); abort_unless(password != NULL, "returned NULL!"); - result = Curl_parsenetrc("example.com", &login, &password, filename); + result = Curl_parsenetrc("example.com", &login, &password, arg); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(strncmp(password, "passwd", 6) == 0, @@ -167,8 +157,7 @@ UNITTEST_START free(login); login = strdup(""); abort_unless(login != NULL, "returned NULL!"); - result = Curl_parsenetrc("curl.example.com", &login, &password, - filename); + result = Curl_parsenetrc("curl.example.com", &login, &password, arg); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(strncmp(password, "none", 4) == 0, @@ -183,8 +172,7 @@ UNITTEST_START free(password); password = strdup(""); abort_unless(password != NULL, "returned NULL!"); - result = Curl_parsenetrc("curl.example.com", &login, &password, - filename); + result = Curl_parsenetrc("curl.example.com", &login, &password, arg); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(strncmp(password, "none", 4) == 0, diff --git a/tests/unit/unit1308.c b/tests/unit/unit1308.c index c213b8f124..3e2cf4b31e 100644 --- a/tests/unit/unit1308.c +++ b/tests/unit/unit1308.c @@ -83,7 +83,7 @@ UNITTEST_START rc = curl_formadd(&post, &last, CURLFORM_PTRNAME, "name of file field", - CURLFORM_FILE, "log/test-1308", + CURLFORM_FILE, arg, CURLFORM_FILENAME, "custom named file", CURLFORM_END); diff --git a/tests/unit/unit1660.c b/tests/unit/unit1660.c index 2836d5d7d5..26c2bfa2df 100644 --- a/tests/unit/unit1660.c +++ b/tests/unit/unit1660.c @@ -125,6 +125,7 @@ UNITTEST_START int i; const char *chost; CURL *easy; + char savename[256]; if(!h) return 1; @@ -136,7 +137,7 @@ UNITTEST_START return 1; } - Curl_hsts_loadfile(easy, h, "log/input1660"); + Curl_hsts_loadfile(easy, h, arg); for(i = 0; headers[i].host ; i++) { if(headers[i].hdr) { @@ -169,7 +170,8 @@ UNITTEST_START deltatime++; /* another second passed */ } - (void)Curl_hsts_save(easy, h, "log/hsts1660"); + msnprintf(savename, sizeof(savename), "%s.save", arg); + (void)Curl_hsts_save(easy, h, savename); Curl_hsts_cleanup(&h); curl_easy_cleanup(easy); curl_global_cleanup(); diff --git a/tests/unit/unit3200.c b/tests/unit/unit3200.c index b15b1efb81..19e1005a03 100644 --- a/tests/unit/unit3200.c +++ b/tests/unit/unit3200.c @@ -24,8 +24,6 @@ #include "curlcheck.h" #include "curl_get_line.h" -#define TESTINPUT "log/curl_get_line2101" - /* The test XML does not supply a way to write files without newlines * so we write our own */ @@ -89,12 +87,12 @@ UNITTEST_START int len = 4096; char *line; - fp = fopen(TESTINPUT, "wb"); + fp = fopen(arg, "wb"); abort_unless(fp != NULL, "Cannot open testfile"); fwrite(filecontents[i], 1, strlen(filecontents[i]), fp); fclose(fp); - fp = fopen(TESTINPUT, "rb"); + fp = fopen(arg, "rb"); abort_unless(fp != NULL, "Cannot open testfile"); fprintf(stderr, "Test %d...", i); -- 2.47.3