11
11
#include < protobuf/testgen.grpc.pb.h>
12
12
13
13
#include < set>
14
+ #include < map>
14
15
15
16
namespace {
16
17
using grpc::Channel;
@@ -105,7 +106,7 @@ namespace {
105
106
{
106
107
std::size_t count{};
107
108
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 ()));
109
110
pos += with.length (), ++count) {
110
111
inout.replace (pos, what.length (), with.data (), with.length ());
111
112
}
@@ -120,8 +121,45 @@ namespace {
120
121
return content;
121
122
}
122
123
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));
125
163
}
126
164
127
165
TEST_F (CLI_Test, Generate_Project_Tests) {
@@ -131,8 +169,9 @@ namespace {
131
169
buildDirectoryName, " project" });
132
170
checkTestDirectory (allProjectTestFiles);
133
171
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);
136
175
}
137
176
138
177
TEST_F (CLI_Test, Generate_File_Tests) {
0 commit comments