From 7427a4506d167e333faf2fbc1002bd6a4feed844 Mon Sep 17 00:00:00 2001 From: Andi Drebes Date: Fri, 16 Sep 2022 11:37:55 +0200 Subject: [PATCH] test(compiler): Abort test if a stream for a YAML file is in a bad state The code in `loadEndToEndDesc` attempts to load the contents of a YAML file without ensuring that the stream from which the file is read was set up correctly. As a result, streams in a bad state, e.g., if the file to be opened does not exist, simply result in an empty string for the file contents. The test driver cannot distinguish this result from a valid YAML file that is simply empty. This patch causes `loadEndToEndDesc` to abort execution whenever a file input stream could not be set up correctly. --- compiler/tests/end_to_end_fixture/EndToEndFixture.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/tests/end_to_end_fixture/EndToEndFixture.cpp b/compiler/tests/end_to_end_fixture/EndToEndFixture.cpp index 53164346a..3dc3ca305 100644 --- a/compiler/tests/end_to_end_fixture/EndToEndFixture.cpp +++ b/compiler/tests/end_to_end_fixture/EndToEndFixture.cpp @@ -284,6 +284,12 @@ LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(EndToEndDesc) std::vector loadEndToEndDesc(std::string path) { std::ifstream file(path); + + if (!file.good()) { + std::cerr << "Could not read yaml file: " << path << std::endl; + assert(false); + } + std::string content((std::istreambuf_iterator(file)), (std::istreambuf_iterator()));