Skip to content

Commit e335563

Browse files
authored
[NFC][flang] Fix execute_command_line test for odd environments (#117714)
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 d3c103b commit e335563

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

flang/unittests/Runtime/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ target_link_libraries(FlangRuntimeTests
3636
FortranRuntime
3737
)
3838

39+
target_compile_definitions(FlangRuntimeTests PRIVATE NOT_EXE="$<TARGET_FILE:not>")
40+
3941
add_subdirectory(CUDA)

flang/unittests/Runtime/CommandTest.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,24 +340,22 @@ TEST_F(ZeroArguments, ECLValidCommandStatusSetSync) {
340340
}
341341

342342
TEST_F(ZeroArguments, ECLGeneralErrorCommandErrorSync) {
343-
OwningPtr<Descriptor> command{CharDescriptor("cat GeneralErrorCommand")};
343+
OwningPtr<Descriptor> command{CharDescriptor(NOT_EXE)};
344344
bool wait{true};
345345
OwningPtr<Descriptor> exitStat{IntDescriptor(404)};
346346
OwningPtr<Descriptor> cmdStat{IntDescriptor(202)};
347347
OwningPtr<Descriptor> cmdMsg{CharDescriptor("cmd msg buffer XXXXXXXXXXXXXX")};
348348

349349
RTNAME(ExecuteCommandLine)
350350
(*command.get(), wait, exitStat.get(), cmdStat.get(), cmdMsg.get());
351-
#if defined(_WIN32)
352351
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 1);
352+
#if defined(_WIN32)
353353
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 6);
354354
CheckDescriptorEqStr(cmdMsg.get(), "Invalid command lineXXXXXXXXX");
355355
#elif defined(_AIX)
356-
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 2);
357356
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 6);
358357
CheckDescriptorEqStr(cmdMsg.get(), "Invalid command lineXXXXXXXXX");
359358
#else
360-
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 1);
361359
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 3);
362360
CheckDescriptorEqStr(cmdMsg.get(), "Command line execution failed");
363361
#endif

0 commit comments

Comments
 (0)