-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
117 lines (101 loc) · 3.51 KB
/
main.cpp
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
#include "libidentify.h"
#include <cstdio>
#include <string>
// framework_ prefix to avoid clashing with reserved words
enum class FrameworkId
{
framework_unknown,
framework_boost,
framework_catch,
framework_google
};
struct IdentificationType
{
explicit IdentificationType()
: frameworkId(FrameworkId::framework_unknown)
{
}
FrameworkId frameworkId;
std::string description;
std::string category;
std::string framework;
std::string version;
};
static char* readLine(std::vector<char>& line, FILE* file)
{
return std::fgets(line.data(), static_cast<int>(line.size()), file);
}
std::string parse(std::vector<char>& line)
{
auto str = std::string(line.data()).substr(16);
return str.substr(0, str.size() - 1);
}
static IdentificationType identify(const std::string& filename)
{
std::string cmd = filename + " --libidentify";
IdentificationType id;
std::vector<char> line(1024);
auto pipe = _popen(cmd.c_str(), "r");
if (readLine(line, pipe) != nullptr)
id.description = parse(line);
if (readLine(line, pipe) != nullptr)
id.category = parse(line);
if (readLine(line, pipe) != nullptr)
id.framework = parse(line);
if (readLine(line, pipe) != nullptr)
id.version = parse(line);
if (id.framework == LibIdentify::framework_boosttest)
id.frameworkId = FrameworkId::framework_boost;
else if (id.framework == LibIdentify::framework_catch)
id.frameworkId = FrameworkId::framework_catch;
else if (id.framework == LibIdentify::framework_googletest)
id.frameworkId = FrameworkId::framework_google;
return id;
}
int main(int argc, char* argv[])
{
//LibIdentify::report("Boost.Test", LibIdentify::category_testframework, LibIdentify::framework_boosttest, "1.64.0", argc, argv);
//LibIdentify::report("Catch C++ Framework", LibIdentify::category_testframework, LibIdentify::framework_catch, "1.9.6", argc, argv);
//LibIdentify::report("Google Test", LibIdentify::category_testframework, LibIdentify::framework_googletest, "1.8.0", argc, argv);
LibIdentify::report("My test description", LibIdentify::category_unspecified, "My unique framework string", "1.0", argc, argv);
if (argc == 2)
{
std::string filename(argv[0]);
std::cout << "Identify: " << filename << std::endl;
auto executableId = identify(filename);
if (executableId.frameworkId == FrameworkId::framework_unknown)
{
std::cout << "Could not identify test framework\n";
exit(1);
}
std::cout << "description: " << executableId.description << std::endl;
std::cout << "category: " << executableId.category << std::endl;
std::cout << "framework: " << executableId.framework << std::endl;
std::cout << "version: " << executableId.version << std::endl;
}
}
void exampleTestMain(int argc, char* argv[])
{
for (int i = 0; i < argc; ++i)
{
auto argument = std::string(argv[i]);
if (argument == "--wait-for-getchar")
{
std::cout << "#waiting" << std::endl;
std::getchar();
return;
}
}
LibIdentify::report("My test description", LibIdentify::category_unspecified, "My unique framework string", "1.0", argc, argv);
/*
... normal main() starts here...
*/
}
/*
console output:
>LibIdentify.exe --libidentify
description: My test description
category: unspecified
framework: My unique framework string
version: 1.0
*/