Skip to content

Commit e14d55b

Browse files
committed
Consider test failing if godot's stdout/sterr contains warning/error logs
1 parent 1918eb3 commit e14d55b

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

tests/run.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818

1919
BASEDIR = Path(__file__).resolve().parent
20+
RED = "\033[0;31m"
21+
GREEN = "\033[0;32m"
22+
YELLOW = "\033[0;33m"
23+
NO_COLOR = "\033[0m"
2024

2125

2226
GodotBinaryVersion = Tuple[str, str, str, str]
@@ -103,7 +107,7 @@ def collect_tests() -> List[Path]:
103107

104108
def install_distrib(build_dir: Path, distrib_subdir: str) -> Path:
105109
distrib_workdir = build_dir / distrib_subdir
106-
print(f"### Generate distrib for tests {distrib_workdir}")
110+
print(f"{YELLOW}Generate distrib for tests {distrib_workdir}{NO_COLOR}")
107111
cmd = [
108112
"meson",
109113
"install",
@@ -165,7 +169,7 @@ def symlink(src: Path, dst: Path) -> None:
165169

166170

167171
def create_test_workdir(test_dir: Path, distrib_workdir: Path, test_workdir: Path) -> None:
168-
print(f"### {test_dir.name}: Create&populate test workdir in {test_workdir}")
172+
print(f"{YELLOW}{test_dir.name}: Create&populate test workdir in {test_workdir}{NO_COLOR}")
169173
shutil.copytree(test_dir, test_workdir, dirs_exist_ok=True)
170174
symlink(distrib_workdir / "addons", test_workdir / "addons")
171175
shutil.copy(distrib_workdir / "pythonscript.gdextension", test_workdir)
@@ -174,7 +178,7 @@ def create_test_workdir(test_dir: Path, distrib_workdir: Path, test_workdir: Pat
174178

175179
build_script = test_workdir / "build.py"
176180
if build_script.exists():
177-
print(f"### {test_dir.name}: Running build script {build_script}")
181+
print(f"{YELLOW}{test_dir.name}: Running build script {build_script}{NO_COLOR}")
178182
cmd = [sys.executable, str(build_script)]
179183
print(" ".join(cmd))
180184
subprocess.check_call(cmd)
@@ -183,10 +187,33 @@ def create_test_workdir(test_dir: Path, distrib_workdir: Path, test_workdir: Pat
183187
def run_test(
184188
test_name: str, test_workdir: Path, godot_binary: Path, extra_args: Sequence[str]
185189
) -> None:
186-
print(f"### {test_name}: Running test in workdir {test_workdir}")
190+
print(f"{YELLOW}{test_name}: Running test in workdir {test_workdir}{NO_COLOR}")
187191
cmd = [str(godot_binary.resolve()), "--path", str(test_workdir.resolve()), *extra_args]
188192
print(" ".join(cmd))
189-
subprocess.check_call(cmd)
193+
res = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
194+
total_output = b""
195+
while True:
196+
buff: bytes = res.stdout.read1()
197+
total_output += buff
198+
os.write(sys.stdout.fileno(), buff)
199+
try:
200+
res.wait(timeout=0.1)
201+
break
202+
except subprocess.TimeoutExpired:
203+
# Subprocess is still running
204+
pass
205+
if res.returncode != 0:
206+
raise SystemExit(f"{RED}{test_name}: Non-zero return code: {res.returncode}{NO_COLOR}")
207+
for line in total_output.splitlines():
208+
# See https://github.com/godotengine/godot/issues/66722
209+
if b"Message Id Number: 0 | Message Id Name: Loader Message" in line:
210+
continue
211+
lower_line = line.lower()
212+
if b"error" in lower_line or b"warning" in lower_line:
213+
raise SystemExit(
214+
f"{RED}{test_name}: stdout/stderr contains logs with error and/or warning ({line}){NO_COLOR}"
215+
)
216+
print(f"{GREEN}{test_name}: All good \\o/{NO_COLOR}")
190217

191218

192219
if __name__ == "__main__":

0 commit comments

Comments
 (0)