]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests: fix 1301, 1308 to fail on error
authorViktor Szakats <commit@vsz.me>
Tue, 8 Jul 2025 20:38:02 +0000 (22:38 +0200)
committerViktor Szakats <commit@vsz.me>
Tue, 8 Jul 2025 22:55:28 +0000 (00:55 +0200)
They were using a macro designed for unit tests. It does not fail when
used in libtests. Make similar macros for these tests, and make them
return a failure.

Also:
- makes these two tests align with the rest of libtests, by including
  `first.h` instead of `curlcheck.h`.
- since libtests no longer need to depend on tests/unit, drop this
  dependency from build scripts.

Closes #17867

tests/libtest/CMakeLists.txt
tests/libtest/Makefile.am
tests/libtest/lib1301.c
tests/libtest/lib1308.c

index 006c46d07e3985a02a1e6fade587938e3b0ffa7f..859f29447d1a20652fea66939ee59bea6c3824c5 100644 (file)
@@ -54,7 +54,6 @@ target_include_directories(${BUNDLE} PRIVATE
   "${PROJECT_BINARY_DIR}/lib"            # for "curl_config.h"
   "${PROJECT_SOURCE_DIR}/lib"            # for "curl_setup.h", curlx
   "${CMAKE_CURRENT_SOURCE_DIR}"          # for the generated bundle source to find included test sources
-  "${PROJECT_SOURCE_DIR}/tests/unit"     # for "curlcheck.h"
 )
 set_property(TARGET ${BUNDLE} APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}")
 set_property(TARGET ${BUNDLE} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_NO_OLDIES" "CURL_DISABLE_DEPRECATION")
index 57e5715038b18002000eecb230e3883ed620782f..ef953466efe06ee94ea90f5b407add34fbd6e71a 100644 (file)
@@ -36,8 +36,7 @@ AUTOMAKE_OPTIONS = foreign nostdinc
 AM_CPPFLAGS = -I$(top_srcdir)/include        \
               -I$(top_builddir)/lib          \
               -I$(top_srcdir)/lib            \
-              -I$(srcdir)                    \
-              -I$(top_srcdir)/tests/unit
+              -I$(srcdir)
 
 # Get BUNDLE, FIRST_C, FIRST_H, UTILS_C, UTILS_H, CURLX_C, TESTS_C variables
 include Makefile.inc
index 81baaeecb1f7e195c714931194bb3d2baeed5f37..0691d6c31f49bd78d2cd87bb8cabb6fd01b48b7f 100644 (file)
  * SPDX-License-Identifier: curl
  *
  ***************************************************************************/
-#include "curlcheck.h"
+#include "first.h"
+
+#define t1301_fail_unless(expr, msg)                             \
+  do {                                                           \
+    if(!(expr)) {                                                \
+      curl_mfprintf(stderr, "%s:%d Assertion '%s' FAILED: %s\n", \
+                    __FILE__, __LINE__, #expr, msg);             \
+      return TEST_ERR_FAILURE;                                   \
+    }                                                            \
+  } while(0)
 
 static CURLcode test_lib1301(char *URL)
 {
@@ -29,25 +38,25 @@ static CURLcode test_lib1301(char *URL)
   (void)URL;
 
   rc = curl_strequal("iii", "III");
-  fail_unless(rc != 0, "return code should be non-zero");
+  t1301_fail_unless(rc != 0, "return code should be non-zero");
 
   rc = curl_strequal("iiia", "III");
-  fail_unless(rc == 0, "return code should be zero");
+  t1301_fail_unless(rc == 0, "return code should be zero");
 
   rc = curl_strequal("iii", "IIIa");
-  fail_unless(rc == 0, "return code should be zero");
+  t1301_fail_unless(rc == 0, "return code should be zero");
 
   rc = curl_strequal("iiiA", "IIIa");
-  fail_unless(rc != 0, "return code should be non-zero");
+  t1301_fail_unless(rc != 0, "return code should be non-zero");
 
   rc = curl_strnequal("iii", "III", 3);
-  fail_unless(rc != 0, "return code should be non-zero");
+  t1301_fail_unless(rc != 0, "return code should be non-zero");
 
   rc = curl_strnequal("iiiABC", "IIIcba", 3);
-  fail_unless(rc != 0, "return code should be non-zero");
+  t1301_fail_unless(rc != 0, "return code should be non-zero");
 
   rc = curl_strnequal("ii", "II", 3);
-  fail_unless(rc != 0, "return code should be non-zero");
+  t1301_fail_unless(rc != 0, "return code should be non-zero");
 
   return CURLE_OK;
 }
index 520054ee219efb757ae79e6934fd778324708b1b..0db7fa84a3879168df539e2abd3095079eb94375 100644 (file)
@@ -21,7 +21,7 @@
  * SPDX-License-Identifier: curl
  *
  ***************************************************************************/
-#include "curlcheck.h"
+#include "first.h"
 
 static size_t print_httppost_callback(void *arg, const char *buf, size_t len)
 {
@@ -30,8 +30,18 @@ static size_t print_httppost_callback(void *arg, const char *buf, size_t len)
   return len;
 }
 
+#define t1308_fail_unless(expr, msg)                             \
+  do {                                                           \
+    if(!(expr)) {                                                \
+      curl_mfprintf(stderr, "%s:%d Assertion '%s' FAILED: %s\n", \
+                    __FILE__, __LINE__, #expr, msg);             \
+      errorcount++;                                              \
+    }                                                            \
+  } while(0)
+
 static CURLcode test_lib1308(char *URL)
 {
+  int errorcount = 0;
   CURLFORMcode rc;
   int res;
   struct curl_httppost *post = NULL;
@@ -41,25 +51,25 @@ static CURLcode test_lib1308(char *URL)
 
   rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
                     CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
-  fail_unless(rc == 0, "curl_formadd returned error");
+  t1308_fail_unless(rc == 0, "curl_formadd returned error");
 
   /* after the first curl_formadd when there's a single entry, both pointers
      should point to the same struct */
-  fail_unless(post == last, "post and last weren't the same");
+  t1308_fail_unless(post == last, "post and last weren't the same");
 
   rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "htmlcode",
                     CURLFORM_COPYCONTENTS, "<HTML></HTML>",
                     CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
-  fail_unless(rc == 0, "curl_formadd returned error");
+  t1308_fail_unless(rc == 0, "curl_formadd returned error");
 
   rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name_for_ptrcontent",
                     CURLFORM_PTRCONTENTS, buffer, CURLFORM_END);
-  fail_unless(rc == 0, "curl_formadd returned error");
+  t1308_fail_unless(rc == 0, "curl_formadd returned error");
 
   res = curl_formget(post, &total_size, print_httppost_callback);
-  fail_unless(res == 0, "curl_formget returned error");
+  t1308_fail_unless(res == 0, "curl_formget returned error");
 
-  fail_unless(total_size == 518, "curl_formget got wrong size back");
+  t1308_fail_unless(total_size == 518, "curl_formget got wrong size back");
 
   curl_formfree(post);
 
@@ -71,14 +81,14 @@ static CURLcode test_lib1308(char *URL)
                     CURLFORM_FILE, URL,
                     CURLFORM_FILENAME, "custom named file",
                     CURLFORM_END);
-  fail_unless(rc == 0, "curl_formadd returned error");
+  t1308_fail_unless(rc == 0, "curl_formadd returned error");
 
   res = curl_formget(post, &total_size, print_httppost_callback);
 
-  fail_unless(res == 0, "curl_formget returned error");
-  fail_unless(total_size == 899, "curl_formget got wrong size back");
+  t1308_fail_unless(res == 0, "curl_formget returned error");
+  t1308_fail_unless(total_size == 899, "curl_formget got wrong size back");
 
   curl_formfree(post);
 
-  return CURLE_OK;
+  return errorcount ? TEST_ERR_FAILURE : CURLE_OK;
 }