svn commit: r1920386 - in /apr/apr-util/branches/1.7.x: ./ test/abts.c test/abts.h

[email protected]
Newsgroups gmane.comp.apache.apr.cvs
Message-ID <[email protected]>
Author: ivan
Date: Mon Sep  2 11:14:49 2024
New Revision: 1920386

URL: http://svn.apache.org/viewvc?rev=1920386&view=rev
Log:
Merge r1877441 from apr/trunk:
* Added support for recording skipped test cases.

Modified:
    apr/apr-util/branches/1.7.x/   (props changed)
    apr/apr-util/branches/1.7.x/test/abts.c
    apr/apr-util/branches/1.7.x/test/abts.h

Propchange: apr/apr-util/branches/1.7.x/
------------------------------------------------------------------------------
  Merged /apr/apr/trunk:r1877441

Modified: apr/apr-util/branches/1.7.x/test/abts.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/test/abts.c?rev=1920386&r1=1920385&r2=1920386&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/test/abts.c (original)
+++ apr/apr-util/branches/1.7.x/test/abts.c Mon Sep  2 11:14:49 2024
@@ -76,6 +76,10 @@ static void end_suite(abts_suite *suite)
             fprintf(stdout, "\b");
             fflush(stdout);
         }
+        if (last->skipped > 0) {
+            fprintf(stdout, "SKIPPED %d of %d\n", last->skipped, last->num_test);
+            fflush(stdout);
+        }
         if (last->failed == 0) {
             fprintf(stdout, "SUCCESS\n");
             fflush(stdout);
@@ -102,6 +106,7 @@ abts_suite *abts_add_suite(abts_suite *s
     subsuite = malloc(sizeof(*subsuite));
     subsuite->num_test = 0;
     subsuite->failed = 0;
+    subsuite->skipped = 0;
     subsuite->next = NULL;
     /* suite_name_full may be an absolute path depending on __FILE__ 
      * expansion */
@@ -164,6 +169,7 @@ void abts_run_test(abts_suite *ts, test_
 
     tc = malloc(sizeof(*tc));
     tc->failed = 0;
+    tc->skipped = 0;
     tc->suite = ss;
     
     ss->num_test++;
@@ -174,12 +180,25 @@ void abts_run_test(abts_suite *ts, test_
     if (tc->failed) {
         ss->failed++;
     }
+    if (tc->skipped) {
+        ss->skipped++;
+    }
     free(tc);
 }
 
+static void report_summary(const char *kind_header,
+                           const char *name_header,
+                           const char *percent_header)
+{
+    fprintf(stdout, "%-15s\t\tTotal\t%s\t%s\n",
+            kind_header, name_header, percent_header);
+    fprintf(stdout, "===================================================\n");
+}
+
 static int report(abts_suite *suite)
 {
-    int count = 0;
+    int failed_count = 0;
+    int skipped_count = 0;
     sub_suite *dptr;
 
     if (suite && suite->tail &&!suite->tail->not_run) {
@@ -187,25 +206,46 @@ static int report(abts_suite *suite)
     }
 
     for (dptr = suite->head; dptr; dptr = dptr->next) {
-        count += dptr->failed;
+        failed_count += dptr->failed;
+    }
+
+    for (dptr = suite->head; dptr; dptr = dptr->next) {
+        skipped_count += dptr->skipped;
     }
 
     if (list_tests) {
         return 0;
     }
 
-    if (count == 0) {
+    /* Report skipped tests */
+    if (skipped_count > 0) {
+        dptr = suite->head;
+        report_summary("Skipped Tests", "Skip", "Skipped %");
+        while (dptr != NULL) {
+            if (dptr->skipped != 0) {
+                float percent = ((float)dptr->skipped / (float)dptr->num_test);
+                fprintf(stdout, "%-15s\t\t%5d\t%4d\t%8.2f%%\n", dptr->name,
+                        dptr->num_test, dptr->skipped, percent * 100);
+            }
+            dptr = dptr->next;
+        }
+    }
+
+    if (failed_count == 0) {
         printf("All tests passed.\n");
         return 0;
     }
 
+    /* Report failed tests */
     dptr = suite->head;
-    fprintf(stdout, "%-15s\t\tTotal\tFail\tFailed %%\n", "Failed Tests");
-    fprintf(stdout, "===================================================\n");
+    if (skipped_count > 0) {
+        fprintf(stdout, "\n");
+    }
+    report_summary("Failed Tests", "Fail", " Failed %");
     while (dptr != NULL) {
         if (dptr->failed != 0) {
             float percent = ((float)dptr->failed / (float)dptr->num_test);
-            fprintf(stdout, "%-15s\t\t%5d\t%4d\t%6.2f%%\n", dptr->name, 
+            fprintf(stdout, "%-15s\t\t%5d\t%4d\t%8.2f%%\n", dptr->name,
                     dptr->num_test, dptr->failed, percent * 100);
         }
         dptr = dptr->next;
@@ -328,7 +368,19 @@ void abts_fail(abts_case *tc, const char
         fflush(stderr);
     }
 }
- 
+
+void abts_skip(abts_case *tc, const char *message, int lineno)
+{
+    update_status();
+    if (tc->skipped) return;
+
+    tc->skipped = TRUE;
+    if (verbose) {
+        fprintf(stderr, "\bSKIP: Line %d: %s\n", lineno, message);
+        fflush(stderr);
+    }
+}
+
 void abts_assert(abts_case *tc, const char *message, int condition, int lineno)
 {
     update_status();

Modified: apr/apr-util/branches/1.7.x/test/abts.h
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/test/abts.h?rev=1920386&r1=1920385&r2=1920386&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/test/abts.h (original)
+++ apr/apr-util/branches/1.7.x/test/abts.h Mon Sep  2 11:14:49 2024
@@ -43,6 +43,7 @@ struct sub_suite {
     const char *name;
     int num_test;
     int failed;
+    int skipped;
     int not_run;
     int not_impl;
     struct sub_suite *next;
@@ -57,6 +58,7 @@ typedef struct abts_suite abts_suite;
 
 struct abts_case {
     int failed;
+    int skipped;
     sub_suite *suite;
 };
 typedef struct abts_case abts_case;
@@ -78,6 +80,7 @@ void abts_ptr_notnull(abts_case *tc, con
 void abts_ptr_equal(abts_case *tc, const void *expected, const void *actual, int lineno);
 void abts_true(abts_case *tc, int condition, int lineno);
 void abts_fail(abts_case *tc, const char *message, int lineno);
+void abts_skip(abts_case *tc, const char *message, int lineno);
 void abts_not_impl(abts_case *tc, const char *message, int lineno);
 void abts_assert(abts_case *tc, const char *message, int condition, int lineno);
 
@@ -93,6 +96,13 @@ void abts_assert(abts_case *tc, const ch
 #define ABTS_NOT_IMPL(a, b)         abts_not_impl(a, b, __LINE__);
 #define ABTS_ASSERT(a, b, c)        abts_assert(a, b, c, __LINE__);
 
+/* When skipping tests, make a reference to the test data parameter
+   to avoid unused variable warnings. */
+#define ABTS_SKIP(tc, data, msg) do {     \
+        ((void)(data));                   \
+        abts_skip((tc), (msg), __LINE__); \
+    } while (0)
+
 #endif
 
 #ifdef __cplusplus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.