1111#include < protobuf/testgen.grpc.pb.h>
1212
1313#include < set>
14+ #include < map>
1415
1516namespace {
1617 using grpc::Channel;
@@ -105,7 +106,7 @@ namespace {
105106 {
106107 std::size_t count{};
107108 for (std::string::size_type pos{};
108- inout. npos != (pos = inout.find (what.data (), pos, what.length ()));
109+ std::string:: npos != (pos = inout.find (what.data (), pos, what.length ()));
109110 pos += with.length (), ++count) {
110111 inout.replace (pos, what.length (), with.data (), with.length ());
111112 }
@@ -120,8 +121,45 @@ namespace {
120121 return content;
121122 }
122123
123- void compareFiles (const fs::path &golden, const fs::path &real) {
124- ASSERT_EQ (getNormalizedContent (golden), getNormalizedContent (real));
124+ std::string filterUnstableParams (const std::string &context) {
125+ std::stringstream ins (context);
126+ std::stringstream outs;
127+ std::string line;
128+ while (getline (ins, line)) {
129+ if (line.find (R"x( "startLine")x" ) != std::string::npos) {
130+ outs << " [startLine replacement]" << " \n " ;
131+ } else if (line.find (R"x( (test)")x" ) != std::string::npos) {
132+ outs << " [test name replacement]" << " \n " ;
133+ } else {
134+ outs << line;
135+ }
136+ }
137+ return outs.str ();
138+ }
139+
140+ std::map<std::string, std::string> getOrderedRecords (const json &rep) {
141+ json results = rep[" runs" ][0 ][" results" ];
142+ std::map<std::string, std::string> records;
143+ for (const auto &it : results) {
144+ std::string problemDescription = it[" message" ][" text" ];
145+
146+ std::string srcFile = it[" locations" ][0 ][" physicalLocation" ][" artifactLocation" ][" uri" ];
147+ int lineNo = it[" locations" ][0 ][" physicalLocation" ][" region" ][" startLine" ];
148+
149+ std::stringstream key;
150+ key << problemDescription << " \n "
151+ << srcFile << " :" << lineNo;
152+
153+ records.insert (std::pair (key.str (), filterUnstableParams (it.dump (2 ))));
154+ }
155+ return records;
156+ }
157+
158+ void compareSARIFFiles (const fs::path &golden, const fs::path &real) {
159+ json gjs = json::parse (getNormalizedContent (golden));
160+ json rjs = json::parse (getNormalizedContent (real));
161+
162+ EXPECT_EQ (getOrderedRecords (gjs), getOrderedRecords (rjs));
125163 }
126164
127165 TEST_F (CLI_Test, Generate_Project_Tests) {
@@ -131,8 +169,9 @@ namespace {
131169 buildDirectoryName, " project" });
132170 checkTestDirectory (allProjectTestFiles);
133171
134- compareFiles ( suitePath / " goldenImage" / sarif::SARIF_DIR_NAME / sarif::SARIF_FILE_NAME,
135- suitePath / sarif::SARIF_DIR_NAME / sarif::SARIF_FILE_NAME);
172+ compareSARIFFiles (
173+ suitePath / " goldenImage" / sarif::SARIF_DIR_NAME /sarif::SARIF_FILE_NAME,
174+ suitePath / sarif::SARIF_DIR_NAME / sarif::SARIF_FILE_NAME);
136175 }
137176
138177 TEST_F (CLI_Test, Generate_File_Tests) {
0 commit comments