@@ -45,44 +45,61 @@ std::pair<PrimitiveInteger, PrimitiveInteger> Type::getRange() const {
4545 return { 0 , 0 };
4646}
4747
48- void Test::print (std::ostream &ss) const {
49- ss << " TEST(" << signature.name << " Test, " << name << " ) {\n " ;
50- ss << " ASSERT_EQ(" ;
51- printFunctionCall (ss);
52- ss << " , " << signature.returnType ->printValue (resultMacroName ()) << " );\n " ;
53- ss << " }\n " ;
54- }
48+ std::string quote (const std::string& s) {
49+ std::stringstream ss;
50+
51+ ss << ' "' ;
52+ bool inEscape = false ;
53+
54+ for (char c : s) {
55+ if (c == ' \n ' ) ss << " \\ n" ;
56+ else if (c == ' \t ' ) ss << " \\ t" ;
57+ else if (c == ' "' ) ss << " \\\" " ;
58+ else if (c == ' \0 ' ) {
59+ inEscape = !inEscape;
60+ if (inEscape) {
61+ ss << " \" << " ;
62+ } else {
63+ ss << " << \" " ;
64+ }
65+ } else ss << c;
66+ }
67+
68+ ss << ' "' ;
5569
56- std::string Test::resultMacroName () const {
57- return " FUZZ_TEST_" + name;
70+ return ss.str ();
5871}
5972
60- void Test::printPreludeGenerator (std::ostream &ss) const {
61- auto macro = resultMacroName ();
62- auto var = macro + " _result" ;
63- ss << " auto " << var << " = " ;
64- printFunctionCall (ss);
65- ss << " ;\n " ;
73+ std::string Test::print () const {
74+ std::stringstream ss;
75+ auto call = printFunctionCall ();
76+ ss << " TEST(" << signature.name << " Test, " << name << " ) {\n " ;
77+ ss << " ASSERT_EQ(" << call;
78+ ss << " , " << signature.returnType ->printValue (' \0 ' + call + ' \0 ' ) << " );\n " ;
79+ ss << " }\n " ;
80+ return ss.str ();
81+ }
6682
67- ss << " std::cout << \" #define " << macro << " \" << " << var << " << \"\\ n\"\n " ;
83+ std::string Test::printGenerator () const {
84+ return " std::cout << " + quote (print ()) + " ;\n " ;
6885}
6986
70- void Test::printFunctionCall (std::ostream &ss) const {
71- ss << signature.name << " (" ;
87+ std::string Test::printFunctionCall () const {
88+ std::string res;
89+ res += signature.name + " (" ;
7290
7391 bool first = true ;
7492
7593 for (const auto &arg : arguments) {
7694 if (!first) {
77- ss << " , " ;
95+ res += " , " ;
7896 }
79-
80- ss << arg.print ();
81-
97+ res += arg.print ();
8298 first = false ;
8399 }
84100
85- ss << " )" ;
101+ res += " )" ;
102+ return res;
86103}
87104
88105std::string printPrimitiveType (PrimitiveType type) {
@@ -112,3 +129,21 @@ Type::ptr primitiveType(PrimitiveType type, PrimitiveInteger min, PrimitiveInteg
112129Type::ptr pointerTo (Type::ptr type) {
113130 return std::make_shared<Type>(Type { PointerTo { std::move (type) } } );
114131}
132+
133+ std::string TestSignature::print () const {
134+ std::string res = returnType->print () + " " + name;
135+ res += " (" ;
136+
137+ bool first = true ;
138+
139+ for (const auto &type : parameterTypes) {
140+ if (!first) {
141+ res += " , " ;
142+ }
143+ first = false ;
144+ res += type->print ();
145+ }
146+
147+ res += " );\n " ;
148+ return res;
149+ }
0 commit comments