mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:01:07 +01:00
Detect invalid yaml. (#3239)
Previous code could fail silently, only caught with yaml output mismatches. This uses ErrorOr to be explicit about the error detection; recovery isn't supported because we should only print valid yaml (in tests, at least). Also moves the test helpers from //toolchain/base to //toolchain/testing. Switches tree_test to use the matchers so that, on mismatch, gtest prints a path to the mismatch (the straight value means it was just printing "not equal"). Addresses https://github.com/carbon-language/carbon-lang/pull/3217#discussion_r1323586836
This commit is contained in:
@@ -15,10 +15,12 @@
|
||||
#include "llvm/Object/Binary.h"
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
#include "testing/base/test_raw_ostream.h"
|
||||
#include "toolchain/testing/yaml_test_helpers.h"
|
||||
|
||||
namespace Carbon::Testing {
|
||||
namespace {
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::ContainsRegex;
|
||||
using ::testing::HasSubstr;
|
||||
using ::testing::StrEq;
|
||||
@@ -125,7 +127,8 @@ TEST_F(DriverTest, DumpTokens) {
|
||||
driver_.RunCommand({"compile", "--phase=lex", "--dump-tokens", file}));
|
||||
EXPECT_THAT(test_error_stream_.TakeStr(), StrEq(""));
|
||||
// Verify there is output without examining it.
|
||||
EXPECT_FALSE(test_output_stream_.TakeStr().empty());
|
||||
EXPECT_THAT(Yaml::Value::FromText(test_output_stream_.TakeStr()),
|
||||
Yaml::IsYaml(_));
|
||||
}
|
||||
|
||||
TEST_F(DriverTest, DumpParseTree) {
|
||||
@@ -134,7 +137,8 @@ TEST_F(DriverTest, DumpParseTree) {
|
||||
{"compile", "--phase=parse", "--dump-parse-tree", file}));
|
||||
EXPECT_THAT(test_error_stream_.TakeStr(), StrEq(""));
|
||||
// Verify there is output without examining it.
|
||||
EXPECT_FALSE(test_output_stream_.TakeStr().empty());
|
||||
EXPECT_THAT(Yaml::Value::FromText(test_output_stream_.TakeStr()),
|
||||
Yaml::IsYaml(_));
|
||||
}
|
||||
|
||||
TEST_F(DriverTest, StdoutOutput) {
|
||||
|
||||
Reference in New Issue
Block a user