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

Function main

Help/guide/tutorial/Step10/SimpleTest/SimpleTest.h:69–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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…