Skip to content

Commit de7f997

Browse files
committed
[NFC][flang] Fix execute_command_line test for odd environments
One of the execute_command_line tests currently runs `cat` on an invalid file and checks its return value, but since we don't control `cat` or the user's path, the return value might not be reliably stable on a per-platform basis. For example, if `git` is installed on Windows in certain configurations it adds a directory to the path containing a `cat` with a different set of error codes to the default Windows one. This patch changes the test to use the `not` binary built by LLVM for testing purposes, which should always return 1 on any platform regardless of the user's environment.
1 parent f94bd3c commit de7f997

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

flang/unittests/Runtime/CommandTest.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "flang/Runtime/execute.h"
1414
#include "flang/Runtime/extensions.h"
1515
#include "flang/Runtime/main.h"
16+
#include "llvm/Support/FileSystem.h"
17+
#include "llvm/Support/Path.h"
1618
#include <cstddef>
1719
#include <cstdlib>
1820

@@ -340,24 +342,26 @@ TEST_F(ZeroArguments, ECLValidCommandStatusSetSync) {
340342
}
341343

342344
TEST_F(ZeroArguments, ECLGeneralErrorCommandErrorSync) {
343-
OwningPtr<Descriptor> command{CharDescriptor("cat GeneralErrorCommand")};
345+
llvm::SmallString<64> cmd;
346+
if (std::error_code ec = llvm::sys::fs::current_path(cmd))
347+
FAIL() << "Failed to obtain the current working directory";
348+
llvm::sys::path::append(cmd, "bin", "not");
349+
OwningPtr<Descriptor> command{CharDescriptor(cmd.data())};
344350
bool wait{true};
345351
OwningPtr<Descriptor> exitStat{IntDescriptor(404)};
346352
OwningPtr<Descriptor> cmdStat{IntDescriptor(202)};
347353
OwningPtr<Descriptor> cmdMsg{CharDescriptor("cmd msg buffer XXXXXXXXXXXXXX")};
348354

349355
RTNAME(ExecuteCommandLine)
350356
(*command.get(), wait, exitStat.get(), cmdStat.get(), cmdMsg.get());
351-
#if defined(_WIN32)
352357
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 1);
358+
#if defined(_WIN32)
353359
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 6);
354360
CheckDescriptorEqStr(cmdMsg.get(), "Invalid command lineXXXXXXXXX");
355361
#elif defined(_AIX)
356-
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 2);
357362
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 6);
358363
CheckDescriptorEqStr(cmdMsg.get(), "Invalid command lineXXXXXXXXX");
359364
#else
360-
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 1);
361365
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 3);
362366
CheckDescriptorEqStr(cmdMsg.get(), "Command line execution failed");
363367
#endif

0 commit comments

Comments
 (0)