[flang][driver] Refactor one unit-test case to use fixtures (nfc)
Move the unit test from InputOutputTest.cpp to FrontendActionTest.cpp
and re-implement it in terms of the FrontendActionTest fixture. This is
just a small code clean-up and a continuation of:
* https://reviews.llvm.org/D93544
Moving forward, we should try be implementing all unit-test cases for
Flang's frontend actions in terms of FrontendActionTest.
Reviewed By: sameeranjoshi
Differential Revision: https://reviews.llvm.org/D94922
diff --git a/flang/unittests/Frontend/FrontendActionTest.cpp b/flang/unittests/Frontend/FrontendActionTest.cpp
index 2e8bacd..fba4669 100644
--- a/flang/unittests/Frontend/FrontendActionTest.cpp
+++ b/flang/unittests/Frontend/FrontendActionTest.cpp
@@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//
-#include "gtest/gtest.h"
#include "flang/Frontend/CompilerInstance.h"
#include "flang/Frontend/CompilerInvocation.h"
#include "flang/Frontend/FrontendOptions.h"
@@ -14,6 +13,8 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+
using namespace Fortran::frontend;
namespace {
@@ -79,6 +80,31 @@
}
};
+TEST_F(FrontendActionTest, TestInputOutput) {
+ // Populate the input file with the pre-defined input and flush it.
+ *(inputFileOs_) << "End Program arithmetic";
+ inputFileOs_.reset();
+
+ // Set-up the action kind.
+ compInst_.invocation().frontendOpts().programAction_ = InputOutputTest;
+
+ // Set-up the output stream. Using output buffer wrapped as an output
+ // stream, as opposed to an actual file (or a file descriptor).
+ llvm::SmallVector<char, 256> outputFileBuffer;
+ std::unique_ptr<llvm::raw_pwrite_stream> outputFileStream(
+ new llvm::raw_svector_ostream(outputFileBuffer));
+ compInst_.set_outputStream(std::move(outputFileStream));
+
+ // Execute the action.
+ bool success = ExecuteCompilerInvocation(&compInst_);
+
+ // Validate the expected output.
+ EXPECT_TRUE(success);
+ EXPECT_TRUE(!outputFileBuffer.empty());
+ EXPECT_TRUE(llvm::StringRef(outputFileBuffer.data())
+ .startswith("End Program arithmetic"));
+}
+
TEST_F(FrontendActionTest, PrintPreprocessedInput) {
// Populate the input file with the pre-defined input and flush it.
*(inputFileOs_) << "#ifdef NEW\n"