[flang-commits] [flang] [NFC][flang] Fix execute_command_line test for odd environments (PR #117714)
David Truby via flang-commits
flang-commits at lists.llvm.org
Tue Nov 26 05:57:38 PST 2024
https://github.com/DavidTruby created https://github.com/llvm/llvm-project/pull/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.
>From de7f99739dd3cd97b729c353f7b66107ba4148ce Mon Sep 17 00:00:00 2001
From: David Truby <david at truby.dev>
Date: Tue, 26 Nov 2024 13:48:41 +0000
Subject: [PATCH] [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.
---
flang/unittests/Runtime/CommandTest.cpp | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/flang/unittests/Runtime/CommandTest.cpp b/flang/unittests/Runtime/CommandTest.cpp
index b0c43ba01d8f33..34a6296d9cdf57 100644
--- a/flang/unittests/Runtime/CommandTest.cpp
+++ b/flang/unittests/Runtime/CommandTest.cpp
@@ -13,6 +13,8 @@
#include "flang/Runtime/execute.h"
#include "flang/Runtime/extensions.h"
#include "flang/Runtime/main.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
#include <cstddef>
#include <cstdlib>
@@ -340,7 +342,11 @@ TEST_F(ZeroArguments, ECLValidCommandStatusSetSync) {
}
TEST_F(ZeroArguments, ECLGeneralErrorCommandErrorSync) {
- OwningPtr<Descriptor> command{CharDescriptor("cat GeneralErrorCommand")};
+ llvm::SmallString<64> cmd;
+ if (std::error_code ec = llvm::sys::fs::current_path(cmd))
+ FAIL() << "Failed to obtain the current working directory";
+ llvm::sys::path::append(cmd, "bin", "not");
+ OwningPtr<Descriptor> command{CharDescriptor(cmd.data())};
bool wait{true};
OwningPtr<Descriptor> exitStat{IntDescriptor(404)};
OwningPtr<Descriptor> cmdStat{IntDescriptor(202)};
@@ -348,16 +354,14 @@ TEST_F(ZeroArguments, ECLGeneralErrorCommandErrorSync) {
RTNAME(ExecuteCommandLine)
(*command.get(), wait, exitStat.get(), cmdStat.get(), cmdMsg.get());
-#if defined(_WIN32)
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 1);
+#if defined(_WIN32)
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 6);
CheckDescriptorEqStr(cmdMsg.get(), "Invalid command lineXXXXXXXXX");
#elif defined(_AIX)
- CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 2);
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 6);
CheckDescriptorEqStr(cmdMsg.get(), "Invalid command lineXXXXXXXXX");
#else
- CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 1);
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 3);
CheckDescriptorEqStr(cmdMsg.get(), "Command line execution failed");
#endif
More information about the flang-commits
mailing list