1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
|
From: Boyuan Yang <byang@debian.org>
Date: Wed, 27 Sep 2023 14:37:28 -0400
Subject: Add back vendor ftest test framework
A tiny test framework used by utfcpp project, handled
as git submodule. This patch adds the files back.
Forwarded: not-needed
---
extern/ftest/.gitignore | 4 +
extern/ftest/LICENSE | 25 ++++
extern/ftest/README.md | 1 +
extern/ftest/ftest.h | 232 ++++++++++++++++++++++++++++++++++++++
extern/ftest/tests/CMakeLists.txt | 23 ++++
extern/ftest/tests/smoke.cpp | 83 ++++++++++++++
6 files changed, 368 insertions(+)
create mode 100644 extern/ftest/.gitignore
create mode 100644 extern/ftest/LICENSE
create mode 100644 extern/ftest/README.md
create mode 100644 extern/ftest/ftest.h
create mode 100644 extern/ftest/tests/CMakeLists.txt
create mode 100644 extern/ftest/tests/smoke.cpp
diff --git a/extern/ftest/.gitignore b/extern/ftest/.gitignore
new file mode 100644
index 0000000..db63970
--- /dev/null
+++ b/extern/ftest/.gitignore
@@ -0,0 +1,4 @@
+# VS Code:
+.vscode/
+# Often used by CMake
+build/
diff --git a/extern/ftest/LICENSE b/extern/ftest/LICENSE
new file mode 100644
index 0000000..f1bad2a
--- /dev/null
+++ b/extern/ftest/LICENSE
@@ -0,0 +1,25 @@
+// Copyright 2021 Nemanja Trifunovic
+
+/*
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+*/
diff --git a/extern/ftest/README.md b/extern/ftest/README.md
new file mode 100644
index 0000000..7a0cd70
--- /dev/null
+++ b/extern/ftest/README.md
@@ -0,0 +1 @@
+This is a small and limited testing framework for C++.
\ No newline at end of file
diff --git a/extern/ftest/ftest.h b/extern/ftest/ftest.h
new file mode 100644
index 0000000..a7840af
--- /dev/null
+++ b/extern/ftest/ftest.h
@@ -0,0 +1,232 @@
+// Copyright 2021 Nemanja Trifunovic
+
+/*
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+*/
+
+
+#ifndef F_TEST_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
+#define F_TEST_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
+
+#include <string>
+#include <vector>
+#include <iostream>
+
+namespace ftest
+{
+
+enum TestStatus {None, Success, Failed};
+
+class Test
+{
+public:
+ Test(const char* name, const char* test_case_name) : m_name(name),
+ m_status(None), m_test_case_name(test_case_name) {}
+ virtual ~Test() {}
+ const std::string& name() const { return m_name; }
+ const std::string& case_name() const { return m_test_case_name; }
+ TestStatus status() const { return m_status; }
+ virtual void run()
+ {
+ std::cout << "[ RUN ] " << m_test_case_name << "." << m_name << std::endl;
+ m_status = Success;
+ run_internal(m_status);
+ if (m_status == Success) {
+ std::cout << "[ OK ] " << m_test_case_name << "." << m_name << std::endl;
+ } else {
+ std::cout << "[ FAILED ] " << m_test_case_name << "." << m_name << std::endl;
+ }
+ }
+protected:
+ virtual void run_internal(TestStatus& status) = 0;
+private:
+ std::string m_name;
+ TestStatus m_status;
+ std::string m_test_case_name;
+};
+
+class TestCase
+{
+public:
+ explicit TestCase(const char* name) : m_name(name) {}
+ const std::string& name() const { return m_name; }
+ void add_test(Test* test) { m_tests.push_back(test); }
+ size_t tests_count() const { return m_tests.size(); }
+ size_t status_count(TestStatus status) const
+ {
+ size_t ret = 0;
+ for (size_t i = 0; i < m_tests.size(); ++i)
+ if (m_tests[i]->status() == status)
+ ++ret;
+ return ret;
+ }
+ void run()
+ {
+ std::cout << "[----------] " << m_tests.size() << " tests from " << name() << std::endl;
+ for (size_t i = 0; i < m_tests.size(); ++i)
+ m_tests[i]->run();
+ std::cout << "[----------] " << m_tests.size() << " tests from " << name() << std::endl;
+ }
+ void print_failed()
+ {
+ for (size_t i = 0; i < m_tests.size(); ++i)
+ if (m_tests[i]->status() == Failed)
+ std::cout << "[ FAILED ] " << m_name << "." << m_tests[i]->name() << std::endl;
+ }
+private:
+ std::string m_name;
+ std::vector<Test*> m_tests;
+};
+
+inline TestCase* find_test_case(const std::string& name, const std::vector<TestCase*>& test_cases)
+{
+ for (size_t i = 0; i < test_cases.size(); ++i) {
+ if (test_cases[i]->name() == name)
+ return test_cases[i];
+ }
+ return 0;
+}
+
+class TestDriver
+{
+public:
+ bool add_test(Test* test)
+ {
+ m_tests.push_back(test);
+ TestCase* test_case = find_test_case(test->case_name(), m_test_cases);
+ if (!test_case) {
+ test_case = new TestCase(test->case_name().c_str());
+ m_test_cases.push_back(test_case);
+ }
+ test_case->add_test(test);
+ return true;
+ }
+
+ int run_tests()
+ {
+ std::cout << "[==========] Running " << m_tests.size() <<
+ " tests from " << m_test_cases.size() << " test cases.\n";
+
+ for (size_t i = 0; i < m_test_cases.size(); ++i)
+ m_test_cases[i]->run();
+
+ std::cout << "[==========] " << m_tests.size() <<
+ " tests from " << m_test_cases.size() << " test cases ran.\n";
+ size_t passed_count = 0, failed_count = 0;
+ for (size_t i = 0; i < m_test_cases.size(); ++i) {
+ passed_count += m_test_cases[i]->status_count(Success);
+ failed_count += m_test_cases[i]->status_count(Failed);
+ }
+ if (passed_count)
+ std::cout << "[ PASSED ] " << passed_count << " tests.\n";
+ if (failed_count) {
+ std::cout << "[ FAILED ] " << failed_count << " tests, listed below:\n";
+ for (size_t i = 0; i < m_test_cases.size(); ++i)
+ m_test_cases[i]->print_failed();
+ std::cout << "\n " << failed_count << " FAILED TESTS\n";
+ }
+
+ return static_cast<int>(failed_count);
+ }
+
+ const std::vector<TestCase*>& test_cases() const { return m_test_cases; }
+
+ ~TestDriver()
+ {
+ for (size_t i = 0; i < m_test_cases.size(); ++i)
+ delete m_test_cases[i];
+ for (size_t i = 0; i < m_tests.size(); ++i)
+ delete m_tests[i];
+ }
+private:
+ std::vector<TestCase*> m_test_cases;
+ std::vector<Test*> m_tests;
+};
+
+#ifdef F_TEST_NO_MAIN
+extern TestDriver testdriver;
+#else
+TestDriver testdriver;
+#endif
+
+} // namespace ftest
+
+#define EXPECT_TRUE(what) \
+do { \
+ if (!(what)) {\
+ std::cout << __FILE__ << ":" << __LINE__ << ": Failure\n"; \
+ std::cout << " Expected : true\n Actual : "; \
+ std::cout << (what ? "true" : "false"); \
+ std::cout << std::endl; \
+ status = ftest::Failed; \
+ } \
+} while (false)
+
+#define EXPECT_FALSE(what) \
+do { \
+ if (what) {\
+ std::cout << __FILE__ << ":" << __LINE__ << ": Failure\n"; \
+ std::cout << " Expected : false\n Actual : "; \
+ std::cout << (what ? "true" : "false"); \
+ std::cout << std::endl; \
+ status = ftest::Failed; \
+ } \
+} while (false)
+
+#define FTEST_EXPECT_PREDICATE(a, b, predicate_operator) \
+do { \
+ if (!(a predicate_operator b)) { \
+ std::cout << __FILE__ << ":" << __LINE__ << ": Failure\n"; \
+ status = ftest::Failed; \
+ } \
+} while (false)
+
+#define EXPECT_EQ(a, b) FTEST_EXPECT_PREDICATE(a, b, ==)
+#define EXPECT_NE(a, b) FTEST_EXPECT_PREDICATE(a, b, !=)
+#define EXPECT_LT(a, b) FTEST_EXPECT_PREDICATE(a, b, <)
+#define EXPECT_LE(a, b) FTEST_EXPECT_PREDICATE(a, b, <=)
+#define EXPECT_GT(a, b) FTEST_EXPECT_PREDICATE(a, b, >)
+#define EXPECT_GE(a, b) FTEST_EXPECT_PREDICATE(a, b, >=)
+
+#define TEST(f_test_case_name, f_test_name) \
+class F_TEST_##f_test_case_name##f_test_name : public ftest::Test \
+{ \
+public: \
+ F_TEST_##f_test_case_name##f_test_name(const char* test_name, const char* test_case_name) : \
+ ftest::Test(test_name, test_case_name) {} \
+ void run_internal(ftest::TestStatus& status); \
+ static bool m_registered; \
+}; \
+bool F_TEST_##f_test_case_name##f_test_name::m_registered = \
+ ftest::testdriver.add_test \
+ (new F_TEST_##f_test_case_name##f_test_name(#f_test_name, #f_test_case_name)); \
+void F_TEST_##f_test_case_name##f_test_name::run_internal(ftest::TestStatus& status)
+
+#ifndef F_TEST_NO_MAIN
+int main (int /*argc*/, const char** /*argv*/)
+{
+ return ftest::testdriver.run_tests();
+}
+#endif //F_TEST_NO_MAIN
+
+#endif // F_TEST_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
diff --git a/extern/ftest/tests/CMakeLists.txt b/extern/ftest/tests/CMakeLists.txt
new file mode 100644
index 0000000..dac5274
--- /dev/null
+++ b/extern/ftest/tests/CMakeLists.txt
@@ -0,0 +1,23 @@
+cmake_minimum_required (VERSION 3.0.2)
+project (ftest VERSION 0.0.1 LANGUAGES CXX)
+
+enable_testing()
+
+add_executable(smoke smoke.cpp)
+target_include_directories (smoke PUBLIC
+ ../
+)
+
+set_target_properties(smoke
+ PROPERTIES
+ CXX_STANDARD 98
+ CXX_STANDARD_REQUIRED YES
+ CXX_EXTENSIONS NO)
+
+target_compile_options(smoke PRIVATE
+ $<$<CXX_COMPILER_ID:MSVC>:/W4>
+ $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>)
+
+
+
+add_test(smoke_test smoke)
diff --git a/extern/ftest/tests/smoke.cpp b/extern/ftest/tests/smoke.cpp
new file mode 100644
index 0000000..5f2f4d8
--- /dev/null
+++ b/extern/ftest/tests/smoke.cpp
@@ -0,0 +1,83 @@
+// Copyright 2021 Nemanja Trifunovic
+
+/*
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+*/
+
+#include "ftest.h"
+#include <iostream>
+
+TEST(Simple, simple)
+{
+ EXPECT_TRUE(true);
+ EXPECT_TRUE(1);
+ EXPECT_TRUE(1 < 2);
+ EXPECT_TRUE(2.0 >= 0);
+}
+
+TEST(Simple, expectfalse)
+{
+ EXPECT_FALSE(false);
+ EXPECT_FALSE(1 == 0);
+ EXPECT_FALSE(1 > 2);
+ EXPECT_FALSE(3.4 == 3.41);
+}
+
+TEST(Predicates, expectequal)
+{
+ EXPECT_EQ(1, 1);
+ EXPECT_EQ(true, true);
+}
+
+TEST(Predicates, expectlessthan)
+{
+ EXPECT_LT(-1, 1);
+ EXPECT_LT(2., 2.1);
+}
+
+TEST(Predicates, expectlessorequal)
+{
+ EXPECT_LE(-1, 1);
+ EXPECT_LE(2., 2.1);
+ EXPECT_LE(1, 1);
+}
+
+TEST(Predicates, expectgreaterthan)
+{
+ EXPECT_GT(1, -1);
+ EXPECT_GT(2.2, 2.1);
+}
+
+TEST(Predicates, expectgreaterorequal)
+{
+ EXPECT_GE(1, -1);
+ EXPECT_GE(2.2, 2.1);
+ EXPECT_GE(1, 1);
+}
+
+TEST(Negative, expectnotequal)
+{
+ EXPECT_NE(1, 2);
+ EXPECT_NE(1., 2.);
+ EXPECT_NE(false, true);
+}
|