[libc++] Harden tests against executors not running tests in a shell
authorLouis Dionne <ldionne@apple.com>
Tue, 3 Nov 2020 19:44:47 +0000 (14:44 -0500)
committerLouis Dionne <ldionne@apple.com>
Tue, 3 Nov 2020 21:03:20 +0000 (16:03 -0500)
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.

12 files changed:
libcxx/test/libcxx/selftest/remote-substitutions.sh.cpp
libcxx/test/std/input.output/iostream.objects/check-stderr.sh [new file with mode: 0644]
libcxx/test/std/input.output/iostream.objects/check-stdout.sh [new file with mode: 0644]
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/send-stdin.sh [new file with mode: 0644]
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

index 644086f..dfd4f4b 100644 (file)
@@ -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 (file)
index 0000000..bc800aa
--- /dev/null
@@ -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 (file)
index 0000000..e86f8cc
--- /dev/null
@@ -0,0 +1,4 @@
+program=${1}
+expected_stdout=${2}
+${program} 2>stderr.log >stdout.log
+[ "${expected_stdout}" == "$(cat stdout.log)" ]
index 16f2b85..b14323d 100644 (file)
 
 // 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;
 }
index c2bbd36..fbb59be 100644 (file)
 
 // 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;
 }
index 0e3faba..6e69ae3 100644 (file)
 
 // 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;
 }
index 8f65b95..171ac74 100644 (file)
 
 // 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 (file)
index 0000000..2f93f2d
--- /dev/null
@@ -0,0 +1,3 @@
+program=${1}
+input=${2}
+echo -n ${input} | ${program}
index 3ce65cb..5d705e7 100644 (file)
 
 // 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;
 }
index 197c1bd..ef240c7 100644 (file)
 
 // 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;
 }
index 34a4913..ada1064 100644 (file)
 
 // 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;
 }
index 577b0c9..0d3306b 100644 (file)
 
 // 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;
 }