File tree Expand file tree Collapse file tree 3 files changed +34
-8
lines changed Expand file tree Collapse file tree 3 files changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ int main() {
66 TestSignature max{ " std::max" , { tInt, tInt }, tInt };
77
88 std::mt19937 gen { std::random_device{}() };
9- std::cout << Test::generate (gen, " ExampleTest" , max).print () << std::endl;
9+ auto test = Test::generate (gen, " ExampleTest" , max);
10+ test.print (std::cout);
11+ std::cout << std::endl << std::endl;
12+ test.printPreludeGenerator (std::cout);
13+ std::cout << std::endl << std::endl;
1014 return 0 ;
1115}
Original file line number Diff line number Diff line change @@ -23,10 +23,30 @@ std::string printPrimitiveType(PrimitiveType type) {
2323 return " <unknown>" ;
2424}
2525
26- std::string Test::print () const {
27- std::stringstream ss;
26+ void Test::print (std::ostream &ss) const {
2827 ss << " TEST(" << signature.name << " Test, " << name << " ) {\n " ;
29- ss << " " << signature.name << " (" ;
28+ ss << " ASSERT_EQ(" ;
29+ printFunctionCall (ss);
30+ ss << " , " << resultMacroName () << " );\n " ;
31+ ss << " }\n " ;
32+ }
33+
34+ std::string Test::resultMacroName () const {
35+ return " FUZZ_TEST_" + name;
36+ }
37+
38+ void Test::printPreludeGenerator (std::ostream &ss) const {
39+ auto macro = resultMacroName ();
40+ auto var = macro + " _result" ;
41+ ss << " auto " << var << " = " ;
42+ printFunctionCall (ss);
43+ ss << " ;\n " ;
44+
45+ ss << " std::cout << \" #define " << macro << " \" << " << var << " << \"\\ n\" " ;
46+ }
47+
48+ void Test::printFunctionCall (std::ostream &ss) const {
49+ ss << signature.name << " (" ;
3050
3151 bool first = true ;
3252
@@ -39,7 +59,6 @@ std::string Test::print() const {
3959
4060 first = false ;
4161 }
42- ss << " );\n " ;
43- ss << " }\n " ;
44- return ss.str ();
62+
63+ ss << " )" ;
4564}
Original file line number Diff line number Diff line change @@ -54,7 +54,10 @@ struct Test
5454 // after test launch
5555 std::optional<Value> returnValue;
5656
57- [[nodiscard]] std::string print () const ;
57+ [[nodiscard]] std::string resultMacroName () const ;
58+ void print (std::ostream &) const ;
59+ void printPreludeGenerator (std::ostream &) const ;
60+ void printFunctionCall (std::ostream &) const ;
5861
5962 template <class Generator >
6063 static Test generate (Generator gen, std::string name, TestSignature signature) {
You can’t perform that action at this time.
0 commit comments