Skip to content

Commit eee9587

Browse files
authored
Fix tools tests on Windows (#184)
The commit 89fcc5e introduced some tests for the tools in the tools/ subdirectory that are always run, but these tests were not working on Windows due to the executables ending in .exe and one of the tests being written in bash. This commit fixes those issues by directly using the $<TARGET_FILE> generator expressions to get the executable file names, and rewriting the bash test in python.
1 parent 4cceb23 commit eee9587

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

tools/test/CMakeLists.txt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
# Copy these files to the build directory so that the tests can be run even
22
# without the source directory.
3-
configure_file(test_not.sh test_not.sh
4-
@ONLY)
3+
configure_file(test_not.py test_not.py
4+
COPYONLY)
55

6-
add_executable(ret1 ret1.c)
7-
llvm_test_run(EXECUTABLE "%b/not" "%b/test/ret1")
6+
llvm_test_executable_no_test(ret1 ret1.c)
7+
add_dependencies(ret1 not)
8+
llvm_test_run(EXECUTABLE "$<TARGET_FILE:not>" "$<TARGET_FILE:ret1>")
89
llvm_add_test_for_target(ret1)
910

10-
add_executable(ret0 ret0.c)
11-
llvm_test_run(EXECUTABLE "%b/not" "%b/not" "%b/test/ret0")
11+
llvm_test_executable_no_test(ret0 ret0.c)
12+
add_dependencies(ret0 not)
13+
llvm_test_run(EXECUTABLE "$<TARGET_FILE:not>" "$<TARGET_FILE:not>" "$<TARGET_FILE:ret0>")
1214
llvm_add_test_for_target(ret0)
1315

1416
# Check that expected crashes are handled correctly.
15-
add_executable(abrt abort.c)
16-
llvm_test_run(EXECUTABLE "%b/not" "--crash" "%b/test/abrt")
17+
llvm_test_executable_no_test(abrt abort.c)
18+
add_dependencies(abrt not)
19+
llvm_test_run(EXECUTABLE "$<TARGET_FILE:not>" "--crash" "$<TARGET_FILE:abrt>")
1720
llvm_add_test_for_target(abrt)
1821

1922
# Check that not passes environment variables to the called executable.
20-
add_executable(check_env check_env.c)
21-
llvm_test_run(EXECUTABLE "/bin/bash" "%b/test/test_not.sh %b")
22-
llvm_add_test(test_not.test test_not.sh)
23+
find_package(Python COMPONENTS Interpreter)
24+
llvm_test_executable_no_test(check_env check_env.c)
25+
add_dependencies(check_env not)
26+
llvm_test_run(EXECUTABLE ${Python_EXECUTABLE} "%b/test/test_not.py" "$<TARGET_FILE:not>" "$<TARGET_FILE:check_env>")
27+
llvm_add_test_For_target(check_env)

tools/test/test_not.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
import subprocess
3+
import sys
4+
5+
os.environ["SET_IN_PARENT"] = "something"
6+
out = subprocess.run([sys.argv[1], sys.argv[2]])
7+
sys.exit(out.returncode)

tools/test/test_not.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)