1 //===-- TestRunner.cpp ----------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "TestRunner.h"
13 /// Gets Current Working Directory and tries to create a Tmp Directory
14 static SmallString
<128> initializeTmpDirectory() {
16 if (std::error_code EC
= sys::fs::current_path(CWD
)) {
17 errs() << "Error getting current directory: " << EC
.message() << "!\n";
21 SmallString
<128> TmpDirectory
;
22 sys::path::append(TmpDirectory
, CWD
, "tmp");
23 if (std::error_code EC
= sys::fs::create_directory(TmpDirectory
))
24 errs() << "Error creating tmp directory: " << EC
.message() << "!\n";
29 TestRunner::TestRunner(StringRef TestName
, std::vector
<std::string
> TestArgs
,
30 StringRef ReducedFilepath
)
31 : TestName(TestName
), TestArgs(std::move(TestArgs
)),
32 ReducedFilepath(ReducedFilepath
) {
33 TmpDirectory
= initializeTmpDirectory();
36 /// Runs the interestingness test, passes file to be tested as first argument
37 /// and other specified test arguments after that.
38 int TestRunner::run(StringRef Filename
) {
39 std::vector
<StringRef
> ProgramArgs
;
40 ProgramArgs
.push_back(TestName
);
41 ProgramArgs
.push_back(Filename
);
43 for (auto Arg
: TestArgs
)
44 ProgramArgs
.push_back(Arg
.c_str());
46 Optional
<StringRef
> Redirects
[3]; // STDIN, STDOUT, STDERR
47 int Result
= sys::ExecuteAndWait(TestName
, ProgramArgs
, None
, Redirects
);
50 Error E
= make_error
<StringError
>("Error running interesting-ness test\n",
51 inconvertibleErrorCode());
52 errs() << toString(std::move(E
));