GCC Code Coverage Report


Directory: ../
File: test/util/TestUtil.h
Date: 2024-12-24 01:17:15
Exec Total Coverage
Lines: 0 0 100.0%
Functions: 0 0 -%
Branches: 0 0 -%

Line Branch Exec Source
1 // Copyright (c) 2021-2024 ChilliBits. All rights reserved.
2
3 // GCOV_EXCL_START
4
5 #pragma once
6
7 #include <functional>
8 #include <string>
9 #include <vector>
10 #include <filesystem>
11
12 #include <gtest/gtest.h>
13
14 namespace spice::testing {
15
16 const char *const PATH_TEST_FILES = "./test-files/";
17 static constexpr unsigned int EXPECTED_NUMBER_OF_TESTS = 250;
18 const char *const GDB_READING_SYMBOLS_MESSAGE = "Reading symbols from ";
19 const char *const GDB_INFERIOR_MESSAGE = "[Inferior";
20 extern bool updateRefs;
21 extern bool runBenchmarks;
22 extern bool enableLeakDetection;
23 extern bool skipNonGitHubTests;
24
25 const char *const INPUT_NAME_LINKER_FLAGS = "linker-flags.txt";
26 const char *const INPUT_NAME_CLI_FLAGS = "cli-flags.txt";
27
28 const char *const REF_NAME_SOURCE = "source.spice";
29 const char *const REF_NAME_PARSE_TREE = "parse-tree.dot";
30 const char *const REF_NAME_SYNTAX_TREE = "syntax-tree.dot";
31 const char *const REF_NAME_SYMBOL_TABLE = "symbol-table.json";
32 const char *const REF_NAME_TYPE_REGISTRY = "type-registry.out";
33 const char *const REF_NAME_IR = "ir-code.ll";
34 const char *const REF_NAME_ASM = "assembly.asm";
35 static constexpr const char *const REF_NAME_OPT_IR[5] = {"ir-code-O1.ll", "ir-code-O2.ll", "ir-code-O3.ll", "ir-code-Os.ll", "ir-code-Oz.ll"};
36 const char *const REF_NAME_EXECUTION_OUTPUT = "cout.out";
37 const char *const REF_NAME_GDB_OUTPUT = "debug.out";
38 const char *const REF_NAME_ERROR_OUTPUT = "exception.out";
39 const char *const REF_NAME_WARNING_OUTPUT = "warning.out";
40 const char *const REF_NAME_EXIT_CODE = "exit-code.out";
41
42 const char *const CTL_SKIP_DISABLED = "disabled";
43 const char *const CTL_SKIP_GH = "skip-gh-actions";
44 const char *const CTL_DEBUG_INFO = "with-debug-info";
45 const char *const CTL_RUN_BUILTIN_TESTS = "run-builtin-tests";
46 const char *const CTL_DEBUG_SCRIPT = "debug.gdb";
47 const char *const CTL_LTO = "with-lto";
48
49 struct TestCase {
50 const std::string testSuite;
51 const std::string testName;
52 const std::filesystem::path testPath;
53 };
54
55 // Typedefs
56 typedef const std::function<std::string()> &GetOutputFct;
57 typedef const std::function<void(std::string &expectedOutput, std::string &actualOutput)> &ModifyOutputFct;
58
59 class TestUtil {
60 public:
61 // Public structs
62 struct NameResolver {
63 template <class T> std::string operator()(const ::testing::TestParamInfo<T> &info) const {
64 T testCase = static_cast<T>(info.param);
65 return TestUtil::toCamelCase(testCase.testSuite) + "_" + TestUtil::toCamelCase(testCase.testName);
66 }
67 };
68
69 // Public static methods
70 static std::vector<TestCase> collectTestCases(const char *suiteName, bool useSubDirs);
71 static bool checkRefMatch(
72 const std::filesystem::path &refPath, GetOutputFct getActualOutput,
73 ModifyOutputFct modifyOutputFct = [](std::string &, std::string &) {});
74 static void handleError(const TestCase &testCase, const std::exception &error);
75 static std::vector<std::string> getSubdirs(const std::filesystem::path &basePath);
76 static std::vector<std::string> getFileContentLinesVector(const std::filesystem::path &filePath);
77 static std::string toCamelCase(std::string input);
78 static constexpr const char *getDefaultExecutableName() {
79 #if OS_WINDOWS
80 return ".\\source.exe";
81 #else
82 return "./source";
83 #endif
84 }
85 static bool isDisabled(const TestCase &testCase, bool isGHActions);
86 static void eraseGDBHeader(std::string &gdbOutput);
87 static void eraseLinesBySubstring(std::string &irCode, const char *needle);
88 };
89
90 } // namespace spice::testing
91
92 // GCOV_EXCL_STOP
93