diff options
author | Thomas Lively <tlively@google.com> | 2023-06-23 09:11:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-23 09:11:54 -0700 |
commit | 34c10dca94a4690a27fd89a7c56bddeb9ac7f858 (patch) | |
tree | 60022d22b1a1db776581b00880995cd8f7468d61 | |
parent | 61f70af4bbe9831fe0bf1fc1fd8e9ec05a67e8a5 (diff) | |
download | binaryen-34c10dca94a4690a27fd89a7c56bddeb9ac7f858.tar.gz binaryen-34c10dca94a4690a27fd89a7c56bddeb9ac7f858.tar.bz2 binaryen-34c10dca94a4690a27fd89a7c56bddeb9ac7f858.zip |
Add a gtest fixture for tests checking printed output (#5781)
Such tests all have to handle disabling and re-enabling color output for printed
wast and have to handle parsing input wast, so add a test fixture that makes
these tasks easier.
-rw-r--r-- | test/gtest/cfg.cpp | 13 | ||||
-rw-r--r-- | test/gtest/print-test.h | 28 |
2 files changed, 33 insertions, 8 deletions
diff --git a/test/gtest/cfg.cpp b/test/gtest/cfg.cpp index d4400acc7..b8ff9cb38 100644 --- a/test/gtest/cfg.cpp +++ b/test/gtest/cfg.cpp @@ -1,13 +1,14 @@ #include "analysis/cfg.h" -#include "support/colors.h" -#include "wasm-s-parser.h" +#include "print-test.h" #include "wasm.h" #include "gtest/gtest.h" using namespace wasm; using namespace wasm::analysis; -TEST(CFGTest, Print) { +using CFGTest = PrintTest; + +TEST_F(CFGTest, Print) { auto moduleText = R"wasm( (module (func $foo @@ -69,16 +70,12 @@ TEST(CFGTest, Print) { )cfg"; Module wasm; - SExpressionParser parser(moduleText); - SExpressionWasmBuilder builder(wasm, *(*parser.root)[0], IRProfile::Normal); + parseWast(wasm, moduleText); CFG cfg = CFG::fromFunction(wasm.getFunction("foo")); - bool colors = Colors::isEnabled(); - Colors::setEnabled(false); std::stringstream ss; cfg.print(ss); - Colors::setEnabled(colors); EXPECT_EQ(ss.str(), cfgText); } diff --git a/test/gtest/print-test.h b/test/gtest/print-test.h new file mode 100644 index 000000000..9815c18bb --- /dev/null +++ b/test/gtest/print-test.h @@ -0,0 +1,28 @@ +#include <iostream> + +#include "support/colors.h" +#include "wasm-s-parser.h" +#include "wasm.h" +#include "gtest/gtest.h" + +#ifndef wasm_test_gtest_print_test_h +#define wasm_test_gtest_print_test_h + +// Helper test fixture for parsing wast and checking some printed output. +class PrintTest : public ::testing::Test { + bool colors = Colors::isEnabled(); + +public: + PrintTest() { Colors::setEnabled(false); } + +protected: + void TearDown() override { Colors::setEnabled(colors); } + + void parseWast(wasm::Module& wasm, const std::string& wast) { + wasm::SExpressionParser parser(wast.c_str()); + wasm::SExpressionWasmBuilder builder( + wasm, *(*parser.root)[0], wasm::IRProfile::Normal); + } +}; + +#endif |