tests: fix unit tests to run with a dynamic log directory

Ref: #10818
This commit is contained in:
Dan Fandrich 2023-03-28 22:30:50 -07:00
parent e7a021e135
commit 6e3734f74f
9 changed files with 29 additions and 32 deletions

View File

@ -18,6 +18,9 @@ unittest
<name>
netrc parsing unit tests
</name>
<command>
%LOGDIR/netrc%TESTNUMBER
</command>
<file name="%LOGDIR/netrc%TESTNUMBER">
machine example.com login admin password passwd
machine curl.example.com login none password none

View File

@ -21,6 +21,9 @@ Mime
<name>
formpost unit tests
</name>
<command>
%LOGDIR/test-%TESTNUMBER
</command>
<file name="%LOGDIR/test-%TESTNUMBER">
Piece of the file that is to uploaded as a formpost
</file>

View File

@ -15,7 +15,7 @@ unittest
HSTS
</features>
<file name="%LOGDIR/input%TESTNUMBER">
<file name="%LOGDIR/hsts%TESTNUMBER">
# 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
</name>
<command>
-
%LOGDIR/hsts%TESTNUMBER
</command>
</client>
@ -72,7 +72,7 @@ expire.example [expire.example]: 1548369268
'expire.example' is not HSTS
'expire.example' is not HSTS
</stdout>
<file name="%LOGDIR/hsts%TESTNUMBER" mode="text">
<file name="%LOGDIR/hsts%TESTNUMBER.save" mode="text">
# Your HSTS cache. https://curl.se/docs/hsts.html
# This file was generated by libcurl! Edit at your own risk.
.new.example "unlimited"

View File

@ -18,5 +18,8 @@ unittest
<name>
curl_get_line unit tests
</name>
<command>
%LOGDIR/curl_get_line%TESTNUMBER
</command>
</client>
</testcase>

View File

@ -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.

View File

@ -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,

View File

@ -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);

View File

@ -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();

View File

@ -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);