You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2020/03/20 15:59:02 UTC

[trafficserver] branch master updated: Convert tscore regression tests to Catch unit tests.

This is an automated email from the ASF dual-hosted git repository.

bcall 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 239336a  Convert tscore regression tests to Catch unit tests.
239336a is described below

commit 239336a7054e579d1a497c21f26a347c717ae295
Author: Walter Karas <wk...@verizonmedia.com>
AuthorDate: Thu Mar 19 16:39:45 2020 -0500

    Convert tscore regression tests to Catch unit tests.
---
 src/tscore/Makefile.am                   |  4 +-
 src/tscore/Tokenizer.cc                  | 25 ------------
 src/tscore/Version.cc                    | 40 --------------------
 src/tscore/unit_tests/test_Extendible.cc |  2 +
 src/tscore/unit_tests/test_Tokenizer.cc  | 56 +++++++++++++++++++++++++++
 src/tscore/unit_tests/test_Version.cc    | 65 ++++++++++++++++++++++++++++++++
 6 files changed, 126 insertions(+), 66 deletions(-)

diff --git a/src/tscore/Makefile.am b/src/tscore/Makefile.am
index c342179..36b5fa1 100644
--- a/src/tscore/Makefile.am
+++ b/src/tscore/Makefile.am
@@ -189,7 +189,9 @@ test_tscore_SOURCES = \
 	unit_tests/test_Regex.cc \
 	unit_tests/test_Scalar.cc \
 	unit_tests/test_scoped_resource.cc \
-	unit_tests/test_ts_file.cc
+	unit_tests/test_Tokenizer.cc \
+	unit_tests/test_ts_file.cc \
+	unit_tests/test_Version.cc
 
 if HAS_HKDF
 test_tscore_SOURCES += \
diff --git a/src/tscore/Tokenizer.cc b/src/tscore/Tokenizer.cc
index 068b4e0..dda9435 100644
--- a/src/tscore/Tokenizer.cc
+++ b/src/tscore/Tokenizer.cc
@@ -374,28 +374,3 @@ Tokenizer::ReUse()
   add_node       = &start_node;
   add_index      = 0;
 }
-
-#if TS_HAS_TESTS
-#include "tscore/TestBox.h"
-
-REGRESSION_TEST(libts_Tokenizer)(RegressionTest *test, int /* atype ATS_UNUSED */, int *pstatus)
-{
-  TestBox box(test, pstatus);
-  box = REGRESSION_TEST_PASSED;
-
-  Tokenizer remap(" \t");
-
-  const char *line = "map https://abc.com https://abc.com @plugin=conf_remap.so @pparam=proxy.config.abc='ABC DEF'";
-
-  const char *toks[] = {"map", "https://abc.com", "https://abc.com", "@plugin=conf_remap.so", "@pparam=proxy.config.abc='ABC DEF'"};
-
-  unsigned count = remap.Initialize(const_cast<char *>(line), (COPY_TOKS | ALLOW_SPACES));
-
-  box.check(count == 5, "check that we parsed 5 tokens");
-  box.check(count == remap.count(), "parsed %u tokens, but now we have %u tokens", count, remap.count());
-
-  for (unsigned i = 0; i < count; ++i) {
-    box.check(strcmp(remap[i], toks[i]) == 0, "expected token %u to be '%s' but found '%s'", count, toks[i], remap[i]);
-  }
-}
-#endif
diff --git a/src/tscore/Version.cc b/src/tscore/Version.cc
index 07c72fe..e2fd0e3 100644
--- a/src/tscore/Version.cc
+++ b/src/tscore/Version.cc
@@ -124,43 +124,3 @@ AppVersionInfo::setup(const char *pkg_name, const char *app_name, const char *ap
 
   defined = 1;
 }
-
-#if TS_HAS_TESTS
-#include "tscore/TestBox.h"
-
-/**
- * AppVersionInfo class test.
- */
-REGRESSION_TEST(AppVersionInfo)(RegressionTest *t, int /* atype ATS_UNUSED */, int *pstatus)
-{
-  *pstatus = REGRESSION_TEST_PASSED;
-
-  AppVersionInfo info;
-
-  TestBox tb(t, pstatus);
-
-  const char *errMsgFormat = "wrong build number, expected '%s', got '%s'";
-  const char *bench[][3]   = {// date, time, resulting build number
-                            {"Oct  4 1957", "19:28:34", BUILD_NUMBER},
-                            {"Oct  4 1957", "19:28:34", "100419"},
-                            {"Apr  4 1957", "09:08:04", "040409"},
-                            {" 4 Apr 1957", "09:08:04", "??????"},
-                            {"Apr  4 1957", "09-08-04", "??????"}};
-
-  int benchSize = sizeof(bench) / sizeof(bench[0]);
-
-  if (0 != strlen(BUILD_NUMBER)) {
-    // Since BUILD_NUMBER is defined by a #define directive, it is not
-    // possible to change the version value from inside the regression test.
-    // If not empty BUILD_NUMBER overrides any result, in this case run only
-    // this test (the rest will always fail).
-    info.setup("Apache Traffic Server", "traffic_server", "5.2.1", bench[0][0], bench[0][1], "build_slave", "builder", "");
-    tb.check(0 == strcmp(info.BldNumStr, bench[0][2]), errMsgFormat, bench[0][2], info.BldNumStr);
-  } else {
-    for (int i = 1; i < benchSize; i++) {
-      info.setup("Apache Traffic Server", "traffic_server", "5.2.1", bench[i][0], bench[i][1], "build_slave", "builder", "");
-      tb.check(0 == strcmp(info.BldNumStr, bench[i][2]), errMsgFormat, bench[i][2], info.BldNumStr);
-    }
-  }
-}
-#endif
diff --git a/src/tscore/unit_tests/test_Extendible.cc b/src/tscore/unit_tests/test_Extendible.cc
index a6b0210..2369184 100644
--- a/src/tscore/unit_tests/test_Extendible.cc
+++ b/src/tscore/unit_tests/test_Extendible.cc
@@ -397,6 +397,8 @@ TEST_CASE("Extendible", "")
     CHECK(ref.m_str == "Hello");
   }
 
+  printf("\n");
+
   INFO("Extendible Test Complete")
 }
 
diff --git a/src/tscore/unit_tests/test_Tokenizer.cc b/src/tscore/unit_tests/test_Tokenizer.cc
new file mode 100644
index 0000000..8e25d0f
--- /dev/null
+++ b/src/tscore/unit_tests/test_Tokenizer.cc
@@ -0,0 +1,56 @@
+/** @file
+
+    Tokenizer tests.
+
+    @section license License
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+*/
+
+#include "tscore/Tokenizer.h"
+
+#include <cstdio>
+#include <cstring>
+
+#include <catch.hpp>
+
+TEST_CASE("Tokenizer", "[libts][Tokenizer]")
+{
+  Tokenizer remap(" \t");
+
+  const char *line = "map https://abc.com https://abc.com @plugin=conf_remap.so @pparam=proxy.config.abc='ABC DEF'";
+
+  const char *toks[] = {"map", "https://abc.com", "https://abc.com", "@plugin=conf_remap.so", "@pparam=proxy.config.abc='ABC DEF'"};
+
+  unsigned count = remap.Initialize(const_cast<char *>(line), (COPY_TOKS | ALLOW_SPACES));
+
+  if (count != 5) {
+    std::printf("check that we parsed 5 tokens\n");
+    CHECK(false);
+  }
+  if (count != remap.count()) {
+    std::printf("parsed %u tokens, but now we have %u tokens\n", count, remap.count());
+    CHECK(false);
+  }
+
+  for (unsigned i = 0; i < count; ++i) {
+    if (std::strcmp(remap[i], toks[i]) != 0) {
+      std::printf("expected token %u to be '%s' but found '%s'\n", count, toks[i], remap[i]);
+      CHECK(false);
+    }
+  }
+}
diff --git a/src/tscore/unit_tests/test_Version.cc b/src/tscore/unit_tests/test_Version.cc
new file mode 100644
index 0000000..a962e3c
--- /dev/null
+++ b/src/tscore/unit_tests/test_Version.cc
@@ -0,0 +1,65 @@
+/** @file
+
+    Tokenizer tests.
+
+    @section license License
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+*/
+
+#include "tscore/I_Version.h"
+#include "tscore/ink_config.h"
+
+#include <cstdio>
+#include <cstring>
+
+#include <catch.hpp>
+
+TEST_CASE("AppVersionInfo", "[libts][version]")
+{
+  AppVersionInfo info;
+
+  const char *errMsgFormat = "wrong build number, expected '%s', got '%s'\n";
+  const char *bench[][3]   = {// date, time, resulting build number
+                            {"Oct  4 1957", "19:28:34", BUILD_NUMBER},
+                            {"Oct  4 1957", "19:28:34", "100419"},
+                            {"Apr  4 1957", "09:08:04", "040409"},
+                            {" 4 Apr 1957", "09:08:04", "??????"},
+                            {"Apr  4 1957", "09-08-04", "??????"}};
+
+  int benchSize = sizeof(bench) / sizeof(bench[0]);
+
+  if (0 != std::strlen(BUILD_NUMBER)) {
+    // Since BUILD_NUMBER is defined by a #define directive, it is not
+    // possible to change the version value from inside the regression test.
+    // If not empty BUILD_NUMBER overrides any result, in this case run only
+    // this test (the rest will always fail).
+    info.setup("Apache Traffic Server", "traffic_server", "5.2.1", bench[0][0], bench[0][1], "build_slave", "builder", "");
+    if (0 != std::strcmp(info.BldNumStr, bench[0][2])) {
+      std::printf(errMsgFormat, bench[0][2], info.BldNumStr);
+      CHECK(false);
+    }
+  } else {
+    for (int i = 1; i < benchSize; i++) {
+      info.setup("Apache Traffic Server", "traffic_server", "5.2.1", bench[i][0], bench[i][1], "build_slave", "builder", "");
+      if (0 != std::strcmp(info.BldNumStr, bench[i][2])) {
+        std::printf(errMsgFormat, bench[i][2], info.BldNumStr);
+        CHECK(false);
+      }
+    }
+  }
+}