]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests: fix unit tests to run with a dynamic log directory
authorDan Fandrich <dan@coneharvesters.com>
Wed, 29 Mar 2023 05:30:50 +0000 (22:30 -0700)
committerDan Fandrich <dan@coneharvesters.com>
Thu, 30 Mar 2023 16:53:57 +0000 (09:53 -0700)
Ref: #10818

tests/data/test1304
tests/data/test1308
tests/data/test1660
tests/data/test3200
tests/unit/README.md
tests/unit/unit1304.c
tests/unit/unit1308.c
tests/unit/unit1660.c
tests/unit/unit3200.c

index 438e5886c7026c5177dbc16ffca97064c3f2fb28..afc9aed1e9ff05489e3b14166a1f1997b065eafa 100644 (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
index 9bd5c056d4df186e2d3e9a447f457d92a6c87f9d..7ec1b98840c268b06c0e1077f9bbcae931daf078 100644 (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>
index e21fec47520b45efe7fdaa42ec17f63dddfa5739..f86126d19cf26928e46ecac8e8c9ca1f037db652 100644 (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"
index 0904cd6d6ebbc5f50bda0612bfcc996ccdf7db85..a2f9074019209d9f2e38d6c02b31de0b3cc53b36 100644 (file)
@@ -18,5 +18,8 @@ unittest
  <name>
 curl_get_line unit tests
  </name>
+<command>
+%LOGDIR/curl_get_line%TESTNUMBER
+</command>
 </client>
 </testcase>
index cb3420c64f297b566e301b1f7b3f273598b0fa87..f11119005085637896de9b7313541a5d0931594c 100644 (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.
 
index 2e7e97a760ee029b9851903c4980c1ed43a2d637..cb7f7bb28ab837ecd372de3c82195ee0ad95c575 100644 (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,
index c213b8f124d2071ddf6965d8c8df4b3e81ed3749..3e2cf4b31e8b25d6d202144e8579e2ba64694a33 100644 (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);
 
index 2836d5d7d5fe15756f48e4fb7f3116461437bf71..26c2bfa2df64f9bb8458c1f3530b7f7fd64773b1 100644 (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();
index b15b1efb81e843221acebe1fc03ed70def0fac77..19e1005a033f66c15a276af5aec5cae86ec45ecb 100644 (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);