OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 fprintf(stderr, "\n"); | 244 fprintf(stderr, "\n"); |
245 fprintf(stderr, "Options:\n"); | 245 fprintf(stderr, "Options:\n"); |
246 fprintf(stderr, | 246 fprintf(stderr, |
247 " --failure_list <filename> Use to specify list of tests\n"); | 247 " --failure_list <filename> Use to specify list of tests\n"); |
248 fprintf(stderr, | 248 fprintf(stderr, |
249 " that are expected to fail. File\n"); | 249 " that are expected to fail. File\n"); |
250 fprintf(stderr, | 250 fprintf(stderr, |
251 " should contain one test name per\n"); | 251 " should contain one test name per\n"); |
252 fprintf(stderr, | 252 fprintf(stderr, |
253 " line. Use '#' for comments.\n"); | 253 " line. Use '#' for comments.\n"); |
254 fprintf(stderr, | |
255 " --enforce_recommended Enforce that recommended test\n"); | |
256 fprintf(stderr, | |
257 " cases are also passing. Specify\n"); | |
258 fprintf(stderr, | |
259 " this flag if you want to be\n"); | |
260 fprintf(stderr, | |
261 " strictly conforming to protobuf\n"); | |
262 fprintf(stderr, | |
263 " spec.\n"); | |
264 exit(1); | 254 exit(1); |
265 } | 255 } |
266 | 256 |
267 void ParseFailureList(const char *filename, vector<string>* failure_list) { | 257 void ParseFailureList(const char *filename, vector<string>* failure_list) { |
268 std::ifstream infile(filename); | 258 std::ifstream infile(filename); |
269 | 259 |
270 if (!infile.is_open()) { | 260 if (!infile.is_open()) { |
271 fprintf(stderr, "Couldn't open failure list file: %s\n", filename); | 261 fprintf(stderr, "Couldn't open failure list file: %s\n", filename); |
272 exit(1); | 262 exit(1); |
273 } | 263 } |
274 | 264 |
275 for (string line; getline(infile, line);) { | 265 for (string line; getline(infile, line);) { |
276 // Remove whitespace. | 266 // Remove whitespace. |
277 line.erase(std::remove_if(line.begin(), line.end(), ::isspace), | 267 line.erase(std::remove_if(line.begin(), line.end(), ::isspace), |
278 line.end()); | 268 line.end()); |
279 | 269 |
280 // Remove comments. | 270 // Remove comments. |
281 line = line.substr(0, line.find("#")); | 271 line = line.substr(0, line.find("#")); |
282 | 272 |
283 if (!line.empty()) { | 273 if (!line.empty()) { |
284 failure_list->push_back(line); | 274 failure_list->push_back(line); |
285 } | 275 } |
286 } | 276 } |
287 } | 277 } |
288 | 278 |
289 int main(int argc, char *argv[]) { | 279 int main(int argc, char *argv[]) { |
290 char *program; | 280 char *program; |
291 google::protobuf::ConformanceTestSuite suite; | 281 google::protobuf::ConformanceTestSuite suite; |
292 | 282 |
293 string failure_list_filename; | |
294 vector<string> failure_list; | 283 vector<string> failure_list; |
295 | 284 |
296 for (int arg = 1; arg < argc; ++arg) { | 285 for (int arg = 1; arg < argc; ++arg) { |
297 if (strcmp(argv[arg], "--failure_list") == 0) { | 286 if (strcmp(argv[arg], "--failure_list") == 0) { |
298 if (++arg == argc) UsageError(); | 287 if (++arg == argc) UsageError(); |
299 failure_list_filename = argv[arg]; | |
300 ParseFailureList(argv[arg], &failure_list); | 288 ParseFailureList(argv[arg], &failure_list); |
301 } else if (strcmp(argv[arg], "--verbose") == 0) { | 289 } else if (strcmp(argv[arg], "--verbose") == 0) { |
302 suite.SetVerbose(true); | 290 suite.SetVerbose(true); |
303 } else if (strcmp(argv[arg], "--enforce_recommended") == 0) { | |
304 suite.SetEnforceRecommended(true); | |
305 } else if (argv[arg][0] == '-') { | 291 } else if (argv[arg][0] == '-') { |
306 fprintf(stderr, "Unknown option: %s\n", argv[arg]); | 292 fprintf(stderr, "Unknown option: %s\n", argv[arg]); |
307 UsageError(); | 293 UsageError(); |
308 } else { | 294 } else { |
309 if (arg != argc - 1) { | 295 if (arg != argc - 1) { |
310 fprintf(stderr, "Too many arguments.\n"); | 296 fprintf(stderr, "Too many arguments.\n"); |
311 UsageError(); | 297 UsageError(); |
312 } | 298 } |
313 program = argv[arg]; | 299 program = argv[arg]; |
314 } | 300 } |
315 } | 301 } |
316 | 302 |
317 suite.SetFailureList(failure_list_filename, failure_list); | 303 suite.SetFailureList(failure_list); |
318 ForkPipeRunner runner(program); | 304 ForkPipeRunner runner(program); |
319 | 305 |
320 std::string output; | 306 std::string output; |
321 bool ok = suite.RunSuite(&runner, &output); | 307 bool ok = suite.RunSuite(&runner, &output); |
322 | 308 |
323 fwrite(output.c_str(), 1, output.size(), stderr); | 309 fwrite(output.c_str(), 1, output.size(), stderr); |
324 | 310 |
325 return ok ? EXIT_SUCCESS : EXIT_FAILURE; | 311 return ok ? EXIT_SUCCESS : EXIT_FAILURE; |
326 } | 312 } |
OLD | NEW |