trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [trafficserver] branch master updated: Test: Convert test_Regex.cc to Catch.
Date Sat, 14 Jul 2018 21:26:59 GMT
This is an automated email from the ASF dual-hosted git repository.

amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new a9157d5  Test: Convert test_Regex.cc to Catch.
a9157d5 is described below

commit a9157d575af35a5e79a53a27b740cae667ffb32c
Author: Alan M. Carroll <amc@apache.org>
AuthorDate: Fri Jul 13 22:01:36 2018 -0500

    Test: Convert test_Regex.cc to Catch.
---
 CMakeLists.txt                        |  2 +-
 lib/ts/Makefile.am                    |  2 +-
 lib/ts/{ => unit-tests}/test_Regex.cc | 35 ++++++++++++++++-------------------
 3 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2ae9ce3..e3f6b47 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1137,7 +1137,6 @@ add_library(libtsutil SHARED
         lib/ts/test_Map.cc
         lib/ts/test_PriorityQueue.cc
         lib/ts/test_Ptr.cc
-        lib/ts/test_Regex.cc
         lib/ts/test_Vec.cc
         lib/ts/test_X509HostnameValidator.cc
         lib/ts/TestBox.h
@@ -1168,6 +1167,7 @@ add_executable(test_tslib
 	lib/ts/unit-tests/test_MemArena.cc
 	lib/ts/unit-tests/test_MemSpan.cc
 	lib/ts/unit-tests/test_MT_hashtable.cc
+        lib/ts/unit-tests/test_Regex.cc
 	lib/ts/unit-tests/test_Scalar.cc
 	lib/ts/unit-tests/test_scoped_resource.cc
 	lib/ts/unit-tests/test_TextView.cc
diff --git a/lib/ts/Makefile.am b/lib/ts/Makefile.am
index 4b9d0be..dd30801 100644
--- a/lib/ts/Makefile.am
+++ b/lib/ts/Makefile.am
@@ -256,7 +256,6 @@ test_tsutil_SOURCES = \
 	test_History.cc \
 	test_PriorityQueue.cc \
 	test_Ptr.cc \
-	test_Regex.cc \
 	tests.cc
 
 test_tslib_CPPFLAGS = $(AM_CPPFLAGS)\
@@ -278,6 +277,7 @@ test_tslib_SOURCES = \
 	unit-tests/test_MemSpan.cc \
 	unit-tests/test_MemArena.cc \
 	unit-tests/test_MT_hashtable.cc \
+	unit-tests/test_Regex.cc \
 	unit-tests/test_Scalar.cc \
 	unit-tests/test_scoped_resource.cc \
 	unit-tests/test_TextView.cc 
diff --git a/lib/ts/test_Regex.cc b/lib/ts/unit-tests/test_Regex.cc
similarity index 53%
rename from lib/ts/test_Regex.cc
rename to lib/ts/unit-tests/test_Regex.cc
index c5b279b..a4bacfa 100644
--- a/lib/ts/test_Regex.cc
+++ b/lib/ts/unit-tests/test_Regex.cc
@@ -1,4 +1,5 @@
-/*
+/**
+  @file Test for Regex.cc
 
   @section license License
 
@@ -19,39 +20,35 @@
   limitations under the License.
 */
 
+#include <array>
+#include <string_view>
+
 #include "ts/ink_assert.h"
 #include "ts/ink_defs.h"
 #include "ts/Regex.h"
-#include "ts/TestBox.h"
+#include "catch.hpp"
 
 typedef struct {
-  char subject[100];
+  std::string_view subject;
   bool match;
 } subject_match_t;
 
 typedef struct {
-  char regex[100];
-  subject_match_t tests[4];
+  std::string_view regex;
+  std::array<subject_match_t, 4> tests;
 } test_t;
 
-static const test_t test_data[] = {
-  {"^foo", {{"foo", true}, {"bar", false}, {"foobar", true}, {"foobarbaz", true}}},
-  {"foo$", {{"foo", true}, {"bar", false}, {"foobar", false}, {"foobarbaz", false}}},
-};
+std::array<test_t, 2> test_data{{{{"^foo"}, {{{{"foo"}, true}, {{"bar"}, false}, {{"foobar"},
true}, {{"foobarbaz"}, true}}}},
+                                 {{"foo$"}, {{{{"foo"}, true}, {{"bar"}, false}, {{"foobar"},
false}, {{"foobarbaz"}, false}}}}}};
 
-REGRESSION_TEST(Regex_basic)(RegressionTest *t, int /* atype ATS_UNUSED */, int *pstatus)
+TEST_CASE("Regex", "[libts][Regex]")
 {
-  TestBox box(t, pstatus, REGRESSION_TEST_PASSED);
-
-  for (unsigned int i = 0; i < countof(test_data); i++) {
+  for (auto &item : test_data) {
     Regex r;
+    r.compile(item.regex.data());
 
-    rprintf(t, "Regex: %s\n", test_data[i].regex);
-    r.compile(test_data[i].regex);
-
-    for (unsigned int j = 0; j < countof(test_data[i].tests); j++) {
-      box.check(r.exec(test_data[i].tests[j].subject) == test_data[i].tests[j].match, "Subject:
%s Result: %s\n",
-                test_data[i].tests[j].subject, test_data[i].tests[j].match ? "true" : "false");
+    for (auto &test : item.tests) {
+      REQUIRE(r.exec(test.subject.data()) == test.match);
     }
   }
 }


Mime
View raw message