[libcxx-commits] [libcxx] 8e5156f - [libc++] Harden tests against executors not running tests in a shell
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Nov 3 13:03:44 PST 2020
Author: Louis Dionne
Date: 2020-11-03T16:03:20-05:00
New Revision: 8e5156f6b0d17e2703566a296601706fdc09bccb
URL: https://github.com/llvm/llvm-project/commit/8e5156f6b0d17e2703566a296601706fdc09bccb
DIFF: https://github.com/llvm/llvm-project/commit/8e5156f6b0d17e2703566a296601706fdc09bccb.diff
LOG: [libc++] Harden tests against executors not running tests in a shell
Some executors do not run the tests in a shell, and so assuming that
they can understand shell builtins is wrong. Instead, call Bash
directly to do what we need to do.
This still requires the executor to be able to run Bash, but at least
it does not require it to interpret command lines in the Bash language.
Added:
libcxx/test/std/input.output/iostream.objects/check-stderr.sh
libcxx/test/std/input.output/iostream.objects/check-stdout.sh
libcxx/test/std/input.output/iostream.objects/send-stdin.sh
Modified:
libcxx/test/libcxx/selftest/remote-substitutions.sh.cpp
libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cerr.sh.cpp
libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cin.sh.cpp
libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/clog.sh.cpp
libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cout.sh.cpp
libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcerr.sh.cpp
libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin.sh.cpp
libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wclog.sh.cpp
libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcout.sh.cpp
Removed:
################################################################################
diff --git a/libcxx/test/libcxx/selftest/remote-substitutions.sh.cpp b/libcxx/test/libcxx/selftest/remote-substitutions.sh.cpp
index 644086f83a65..dfd4f4be4888 100644
--- a/libcxx/test/libcxx/selftest/remote-substitutions.sh.cpp
+++ b/libcxx/test/libcxx/selftest/remote-substitutions.sh.cpp
@@ -17,7 +17,7 @@
// RUN: %{cxx} %s %{flags} %{compile_flags} %{link_flags} -o %t.exe
// RUN: %{exec} %t.exe 0
-// RUN: %{exec} ! %t.exe 1
+// RUN: %{exec} bash -c '! %t.exe 1'
#include <cassert>
#include <cstdlib>
diff --git a/libcxx/test/std/input.output/iostream.objects/check-stderr.sh b/libcxx/test/std/input.output/iostream.objects/check-stderr.sh
new file mode 100644
index 000000000000..bc800aa9a6bb
--- /dev/null
+++ b/libcxx/test/std/input.output/iostream.objects/check-stderr.sh
@@ -0,0 +1,4 @@
+program=${1}
+expected_stderr=${2}
+${program} 2>stderr.log >stdout.log
+[ "${expected_stderr}" == "$(cat stderr.log)" ]
diff --git a/libcxx/test/std/input.output/iostream.objects/check-stdout.sh b/libcxx/test/std/input.output/iostream.objects/check-stdout.sh
new file mode 100644
index 000000000000..e86f8cc43a92
--- /dev/null
+++ b/libcxx/test/std/input.output/iostream.objects/check-stdout.sh
@@ -0,0 +1,4 @@
+program=${1}
+expected_stdout=${2}
+${program} 2>stderr.log >stdout.log
+[ "${expected_stdout}" == "$(cat stdout.log)" ]
diff --git a/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cerr.sh.cpp b/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cerr.sh.cpp
index 16f2b85f07e1..b14323d9fd1e 100644
--- a/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cerr.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cerr.sh.cpp
@@ -10,26 +10,23 @@
// istream cerr;
+// FILE_DEPENDENCIES: ../check-stderr.sh
// RUN: %{build}
-// RUN: %{exec} %t.exe 2> %t.err
-// RUN: grep -e 'Hello World!' %t.err
+// RUN: %{exec} bash check-stderr.sh "%t.exe" "1234"
#include <iostream>
#include <cassert>
#include "test_macros.h"
-int main(int, char**)
-{
-
- std::cerr << "Hello World!\n";
+int main(int, char**) {
+ std::cerr << "1234";
+ assert(std::cerr.flags() & std::ios_base::unitbuf);
#ifdef _LIBCPP_HAS_NO_STDOUT
assert(std::cerr.tie() == NULL);
#else
assert(std::cerr.tie() == &std::cout);
#endif
- assert(std::cerr.flags() & std::ios_base::unitbuf);
-
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cin.sh.cpp b/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cin.sh.cpp
index c2bbd360490b..fbb59be56677 100644
--- a/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cin.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cin.sh.cpp
@@ -12,26 +12,16 @@
// istream cin;
+// FILE_DEPENDENCIES: ../send-stdin.sh
// RUN: %{build}
-// RUN: %{exec} echo "123" \| %t.exe > %t.out
-// RUN: grep -e 'The number is 123!' %t.out
+// RUN: %{exec} bash send-stdin.sh "%t.exe" "1234"
#include <iostream>
#include <cassert>
-#include "test_macros.h"
-
-int main(int, char**)
-{
+int main(int, char**) {
int i;
std::cin >> i;
- std::cout << "The number is " << i << "!";
-
-#ifdef _LIBCPP_HAS_NO_STDOUT
- assert(std::cin.tie() == NULL);
-#else
- assert(std::cin.tie() == &std::cout);
-#endif
-
- return 0;
+ assert(i == 1234);
+ return 0;
}
diff --git a/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/clog.sh.cpp b/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/clog.sh.cpp
index 0e3faba853f1..6e69ae3426e8 100644
--- a/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/clog.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/clog.sh.cpp
@@ -10,17 +10,13 @@
// istream clog;
+// FILE_DEPENDENCIES: ../check-stderr.sh
// RUN: %{build}
-// RUN: %{exec} %t.exe 2> %t.err
-// RUN: grep -e 'Hello World!' %t.err
+// RUN: %{exec} bash check-stderr.sh "%t.exe" "1234"
#include <iostream>
-#include "test_macros.h"
-
-int main(int, char**)
-{
- std::clog << "Hello World!\n";
-
+int main(int, char**) {
+ std::clog << "1234";
return 0;
}
diff --git a/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cout.sh.cpp b/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cout.sh.cpp
index 8f65b9523b4a..171ac74593e8 100644
--- a/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cout.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.objects/narrow.stream.objects/cout.sh.cpp
@@ -12,17 +12,13 @@
// istream cout;
+// FILE_DEPENDENCIES: ../check-stdout.sh
// RUN: %{build}
-// RUN: %{exec} %t.exe > %t.out
-// RUN: grep -e 'Hello World!' %t.out
+// RUN: %{exec} bash check-stdout.sh "%t.exe" "1234"
#include <iostream>
-#include "test_macros.h"
-
-int main(int, char**)
-{
- std::cout << "Hello World!\n";
-
+int main(int, char**) {
+ std::cout << "1234";
return 0;
}
diff --git a/libcxx/test/std/input.output/iostream.objects/send-stdin.sh b/libcxx/test/std/input.output/iostream.objects/send-stdin.sh
new file mode 100644
index 000000000000..2f93f2dfa422
--- /dev/null
+++ b/libcxx/test/std/input.output/iostream.objects/send-stdin.sh
@@ -0,0 +1,3 @@
+program=${1}
+input=${2}
+echo -n ${input} | ${program}
diff --git a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcerr.sh.cpp b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcerr.sh.cpp
index 3ce65cb087ac..5d705e7a569c 100644
--- a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcerr.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcerr.sh.cpp
@@ -10,25 +10,23 @@
// istream wcerr;
+// FILE_DEPENDENCIES: ../check-stderr.sh
// RUN: %{build}
-// RUN: %{exec} %t.exe 2> %t.err
-// RUN: grep -e 'Hello World!' %t.err
+// RUN: %{exec} bash check-stderr.sh "%t.exe" "1234"
#include <iostream>
#include <cassert>
#include "test_macros.h"
-int main(int, char**)
-{
- std::wcerr << L"Hello World!\n";
+int main(int, char**) {
+ std::wcerr << L"1234";
+ assert(std::wcerr.flags() & std::ios_base::unitbuf);
#ifdef _LIBCPP_HAS_NO_STDOUT
assert(std::wcerr.tie() == NULL);
#else
assert(std::wcerr.tie() == &std::wcout);
#endif
- assert(std::wcerr.flags() & std::ios_base::unitbuf);
-
return 0;
}
diff --git a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin.sh.cpp b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin.sh.cpp
index 197c1bd6c22b..ef240c76026e 100644
--- a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin.sh.cpp
@@ -12,26 +12,16 @@
// istream wcin;
+// FILE_DEPENDENCIES: ../send-stdin.sh
// RUN: %{build}
-// RUN: %{exec} echo "123" \| %t.exe > %t.out
-// RUN: grep -e 'The number is 123!' %t.out
+// RUN: %{exec} bash send-stdin.sh "%t.exe" "1234"
#include <iostream>
#include <cassert>
-#include "test_macros.h"
-
-int main(int, char**)
-{
+int main(int, char**) {
int i;
std::wcin >> i;
- std::wcout << L"The number is " << i << L"!";
-
-#ifdef _LIBCPP_HAS_NO_STDOUT
- assert(std::wcin.tie() == NULL);
-#else
- assert(std::wcin.tie() == &std::wcout);
-#endif
-
+ assert(i == 1234);
return 0;
}
diff --git a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wclog.sh.cpp b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wclog.sh.cpp
index 34a4913a04c3..ada106449c3b 100644
--- a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wclog.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wclog.sh.cpp
@@ -10,17 +10,13 @@
// istream wclog;
+// FILE_DEPENDENCIES: ../check-stderr.sh
// RUN: %{build}
-// RUN: %{exec} %t.exe 2> %t.err
-// RUN: grep -e 'Hello World!' %t.err
+// RUN: %{exec} bash check-stderr.sh "%t.exe" "1234"
#include <iostream>
-#include "test_macros.h"
-
-int main(int, char**)
-{
- std::wclog << L"Hello World!\n";
-
+int main(int, char**) {
+ std::wclog << L"1234";
return 0;
}
diff --git a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcout.sh.cpp b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcout.sh.cpp
index 577b0c95ba37..0d3306bf62da 100644
--- a/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcout.sh.cpp
+++ b/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcout.sh.cpp
@@ -12,17 +12,13 @@
// istream wcout;
+// FILE_DEPENDENCIES: ../check-stdout.sh
// RUN: %{build}
-// RUN: %{exec} %t.exe > %t.out
-// RUN: grep -e 'Hello World!' %t.out
+// RUN: %{exec} bash check-stdout.sh "%t.exe" "1234"
#include <iostream>
-#include "test_macros.h"
-
-int main(int, char**)
-{
- std::wcout << L"Hello World!\n";
-
+int main(int, char**) {
+ std::wcout << L"1234";
return 0;
}
More information about the libcxx-commits
mailing list