Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cl/427812386 Create a cc_binary to update output files (#37638)
- Loading branch information
1 parent
a4ad3b2
commit 5f0a1e1
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// A binary which runs the validator over golden test input files and overwrites | ||
// all output files. It is useful to update a bunch of test and then inspect | ||
// the diff. | ||
|
||
#include <fstream> | ||
|
||
#include "absl/strings/str_replace.h" | ||
#include "cpp/engine/testing-utils.h" | ||
#include "cpp/engine/validator.h" | ||
|
||
namespace amp::validator { | ||
namespace { | ||
|
||
void UpdateTests() { | ||
for (const auto& entry : testing::TestCases()) { | ||
const testing::TestCase& test_case = entry.second; | ||
ValidationResult result = | ||
Validate(test_case.input_content, test_case.html_format); | ||
std::string output_content = testing::RenderInlineResult( | ||
test_case.name, test_case.input_content, result); | ||
const std::string output_filename = absl::StrReplaceAll( | ||
test_case.output_file, | ||
{{"external/validator/testdata/", "validator/testdata/"}, | ||
{"external/amphtml-extensions/", "extensions/"}}); | ||
if (output_content == test_case.output_content) { | ||
std::cout << "Unchanged validation: " << output_filename << std::endl; | ||
} else { | ||
std::cout << "Updating validation: " << output_filename << std::endl; | ||
std::ofstream output_stream; | ||
output_stream.open(output_filename); | ||
output_stream << output_content; | ||
output_stream.close(); | ||
} | ||
} | ||
} | ||
|
||
} // namespace | ||
} // namespace amp::validator | ||
|
||
int main(int argc, char* argv[]) { | ||
amp::validator::UpdateTests(); | ||
return 0; | ||
} |