2
2
import pathlib
3
3
import subprocess
4
4
import sys
5
+ from typing import Generator
5
6
6
7
SELF_FILE = pathlib .Path (__file__ )
7
- COMMANDS_FILE = SELF_FILE .parent / "commands.sh"
8
8
9
9
10
- def read_commands () -> list [list [str ]]:
11
- return [
12
- line .split ()
13
- for line in COMMANDS_FILE .read_text ().splitlines ()
14
- # Skip empty lines and comments
15
- if line .strip () and not line .strip ().startswith ("#" )
16
- ]
10
+ def find_test_scripts () -> Generator [pathlib .Path , None , None ]:
11
+ for child in SELF_FILE .parent .iterdir ():
12
+ if child .suffix == ".sh" :
13
+ yield child
17
14
18
15
19
- def run_command ( command : list [ str ] ) -> subprocess .CompletedProcess :
16
+ def run_script ( script : pathlib . Path ) -> subprocess .CompletedProcess :
20
17
env = os .environ .copy ()
21
18
# Prepend either the parent uv path to the PATH or the current directory
22
19
env = {
@@ -27,12 +24,14 @@ def run_command(command: list[str]) -> subprocess.CompletedProcess:
27
24
+ os .pathsep
28
25
+ env .get ("PATH" ),
29
26
}
30
- return subprocess .run (command , capture_output = True , text = True , env = env )
27
+ return subprocess .run (
28
+ ["/bin/sh" , str (script .absolute ())], capture_output = True , text = True , env = env
29
+ )
31
30
32
31
33
32
def report_result (result : subprocess .CompletedProcess ):
34
33
print ("=============================================" )
35
- print (f"command : { ' ' . join ( result .args ) } " )
34
+ print (f"script : { result .args [ - 1 ]. rsplit ( os . path . sep , 1 )[ - 1 ] } " )
36
35
print (f"exit code: { result .returncode } " )
37
36
print ()
38
37
print ("------- stdout -------" )
@@ -43,17 +42,17 @@ def report_result(result: subprocess.CompletedProcess):
43
42
44
43
45
44
def main ():
46
- results = [run_command ( command ) for command in read_commands ()]
45
+ results = [run_script ( script ) for script in find_test_scripts ()]
47
46
failed = sum (result .returncode != 0 for result in results )
48
47
for result in results :
49
48
report_result (result )
50
49
51
50
print ("=============================================" )
52
51
if failed :
53
- print (f"FAILURE - { failed } /{ len (results )} commands failed" )
52
+ print (f"FAILURE - { failed } /{ len (results )} scripts failed" )
54
53
sys .exit (1 )
55
54
else :
56
- print (f"SUCCESS - { len (results )} /{ len (results )} commands succeeded" )
55
+ print (f"SUCCESS - { len (results )} /{ len (results )} scripts succeeded" )
57
56
58
57
59
58
main ()
0 commit comments