MCPcopy Create free account
hub / github.com/Kitware/CMake / main

Function main

Help/guide/tutorial/Step11/SimpleTest/SimpleTest.h:71–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69 } while (0)
70
71int main(int argc, char** argv)
72{
73 using namespace ::SimpleTest;
74
75 std::string_view arg1 =
76 (argc >= 2) ? std::string_view{ argv[1] } : std::string_view{};
77
78 if (arg1 == "--list") {
79 bool first = true;
80 for (auto const& [name, _] : registry()) {
81 if (!first)
82 std::printf(",");
83 std::printf("%.*s", int(name.size()), name.data());
84 first = false;
85 }
86 std::printf("\n");
87 return 0;
88 }
89
90 if (arg1 == "--test") {
91 if (argc < 3) {
92 std::printf("usage: %s [--list] [--test <name>]\n", argv[0]);
93 return 2;
94 }
95
96#ifdef SIMPLETEST_CONFIG
97 std::printf("SimpleTest built with config: " SIMPLETEST_XSTRINGIFY(
98 SIMPLETEST_CONFIG) "\n");
99#endif
100
101 std::string_view name{ argv[2] };
102 auto it = registry().find(name);
103 if (it == registry().end()) {
104 std::printf("[ NOTFOUND ] %s\n", argv[2]);
105 return 2;
106 }
107
108 int failed = 0;
109 std::printf("[ RUN ] %.*s\n", int(it->first.size()),
110 it->first.data());
111 try {
112 it->second();
113 std::printf("[ OK] %.*s\n", int(it->first.size()),
114 it->first.data());
115 } catch (failure const& f) {
116 std::printf("[ FAILED ] %.*s at %s:%d : %s\n", int(it->first.size()),
117 it->first.data(), f.file, f.line, f.expr);
118 failed = 1;
119 } catch (...) {
120 std::printf("[ FAILED ] %.*s : unknown exception\n",
121 int(it->first.size()), it->first.data());
122 failed = 1;
123 }
124 return failed;
125 }
126
127 if (argc > 1) {
128 std::printf("usage: %s [--list] [--test <name>]\n", argv[0]);

Callers

nothing calls this directly

Calls 5

funcFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…