Skip to content

Commit

Permalink
[flang][driver] Refactor one unit-test case to use fixtures (nfc)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
banach-space committed Jan 20, 2021
1 parent 8776e3f commit b564b12
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 79 deletions.
1 change: 0 additions & 1 deletion flang/unittests/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
add_flang_unittest(FlangFrontendTests
CompilerInstanceTest.cpp
InputOutputTest.cpp
FrontendActionTest.cpp
)

Expand Down
2 changes: 1 addition & 1 deletion flang/unittests/Frontend/CompilerInstanceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "flang/Frontend/CompilerInstance.h"
#include "flang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "llvm/Support//FileSystem.h"
#include "llvm/Support/FileSystem.h"

#include "gtest/gtest.h"

Expand Down
28 changes: 27 additions & 1 deletion flang/unittests/Frontend/FrontendActionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
//
//===----------------------------------------------------------------------===//

#include "gtest/gtest.h"
#include "flang/Frontend/CompilerInstance.h"
#include "flang/Frontend/CompilerInvocation.h"
#include "flang/Frontend/FrontendOptions.h"
#include "flang/FrontendTool/Utils.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h"

#include "gtest/gtest.h"

using namespace Fortran::frontend;

namespace {
Expand Down Expand Up @@ -79,6 +80,31 @@ class FrontendActionTest : public ::testing::Test {
}
};

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"
Expand Down
76 changes: 0 additions & 76 deletions flang/unittests/Frontend/InputOutputTest.cpp

This file was deleted.

0 comments on commit b564b12

Please sign in to comment.