Skip to content

Commit 6838563

Browse files
Fix & test process_changed_files()
1 parent 23d45f0 commit 6838563

File tree

2 files changed

+157
-2
lines changed

2 files changed

+157
-2
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
"""Tests to cover the Tools/build/compite-changes.py script."""
2+
3+
import importlib
4+
import os
5+
import unittest
6+
from pathlib import Path
7+
from unittest.mock import patch
8+
9+
from test.test_tools import skip_if_missing, imports_under_tool
10+
11+
skip_if_missing("build")
12+
13+
with patch.dict(os.environ, {"GITHUB_DEFAULT_BRANCH": "main"}):
14+
with imports_under_tool("build"):
15+
compute_changes = importlib.import_module("compute-changes")
16+
17+
process_changed_files = compute_changes.process_changed_files
18+
Outputs = compute_changes.Outputs
19+
ANDROID_DIRS = compute_changes.ANDROID_DIRS
20+
IOS_DIRS = compute_changes.IOS_DIRS
21+
MACOS_DIRS = compute_changes.MACOS_DIRS
22+
WASI_DIRS = compute_changes.WASI_DIRS
23+
RUN_TESTS_IGNORE = compute_changes.RUN_TESTS_IGNORE
24+
UNIX_BUILD_SYSTEM_FILE_NAMES = compute_changes.UNIX_BUILD_SYSTEM_FILE_NAMES
25+
LIBRARY_FUZZER_PATHS = compute_changes.LIBRARY_FUZZER_PATHS
26+
27+
28+
class TestProcessChangedFiles(unittest.TestCase):
29+
30+
def test_windows(self):
31+
f = {Path(".github/workflows/reusable-windows.yml")}
32+
result = process_changed_files(f)
33+
self.assertTrue(result.run_tests)
34+
self.assertTrue(result.run_windows_tests)
35+
36+
def test_docs(self):
37+
files = (
38+
".github/workflows/reusable-docs.yml",
39+
"Doc/library/datetime.rst",
40+
"Doc/Makefile"
41+
)
42+
for f in files:
43+
with self.subTest(f=f):
44+
result = process_changed_files({Path(f)})
45+
self.assertTrue(result.run_docs)
46+
self.assertFalse(result.run_tests)
47+
48+
def test_ci_fuzz_stdlib(self):
49+
for p in LIBRARY_FUZZER_PATHS:
50+
with self.subTest(p=p):
51+
if p.is_dir():
52+
f = p / "comhad"
53+
elif p.is_file():
54+
f = p
55+
else:
56+
continue
57+
result = process_changed_files({f})
58+
self.assertTrue(result.run_ci_fuzz_stdlib)
59+
60+
def test_android(self):
61+
for d in ANDROID_DIRS:
62+
with self.subTest(d=d):
63+
result = process_changed_files({Path(d) / "comhad"})
64+
self.assertTrue(result.run_tests)
65+
self.assertTrue(result.run_android)
66+
self.assertFalse(result.run_windows_tests)
67+
68+
def test_ios(self):
69+
for d in IOS_DIRS:
70+
with self.subTest(d=d):
71+
result = process_changed_files({Path(d) / "comhad"})
72+
self.assertTrue(result.run_tests)
73+
self.assertTrue(result.run_ios)
74+
self.assertFalse(result.run_windows_tests)
75+
76+
def test_macos(self):
77+
f = {Path(".github/workflows/reusable-macos.yml")}
78+
result = process_changed_files(f)
79+
self.assertTrue(result.run_tests)
80+
self.assertTrue(result.run_macos)
81+
82+
for d in MACOS_DIRS:
83+
with self.subTest(d=d):
84+
result = process_changed_files({Path(d) / "comhad"})
85+
self.assertTrue(result.run_tests)
86+
self.assertTrue(result.run_macos)
87+
self.assertFalse(result.run_windows_tests)
88+
89+
def test_wasi(self):
90+
f = {Path(".github/workflows/reusable-wasi.yml")}
91+
result = process_changed_files(f)
92+
self.assertTrue(result.run_tests)
93+
self.assertTrue(result.run_wasi)
94+
95+
for d in WASI_DIRS:
96+
with self.subTest(d=d):
97+
result = process_changed_files({d / "comhad"})
98+
self.assertTrue(result.run_tests)
99+
self.assertTrue(result.run_wasi)
100+
self.assertFalse(result.run_windows_tests)
101+
102+
def test_unix(self):
103+
for f in UNIX_BUILD_SYSTEM_FILE_NAMES:
104+
with self.subTest(f=f):
105+
result = process_changed_files({f})
106+
self.assertTrue(result.run_tests)
107+
self.assertFalse(result.run_windows_tests)
108+
109+
def test_msi(self):
110+
files = (
111+
".github/workflows/reusable-windows-msi.yml",
112+
"Tools/msi/build.bat",
113+
)
114+
for f in files:
115+
with self.subTest(f=f):
116+
result = process_changed_files({Path(f)})
117+
self.assertTrue(result.run_windows_msi)
118+
119+
def test_all_run(self):
120+
files = [
121+
".github/workflows/some-new-workflow.yml",
122+
".github/workflows/build.yml",
123+
]
124+
for f in files:
125+
with self.subTest(f=f):
126+
result = process_changed_files({Path(f)})
127+
self.assertTrue(result.run_tests)
128+
self.assertTrue(result.run_android)
129+
self.assertTrue(result.run_ios)
130+
self.assertTrue(result.run_macos)
131+
self.assertTrue(result.run_ubuntu)
132+
self.assertTrue(result.run_wasi)
133+
134+
def test_all_ignored(self):
135+
for f in RUN_TESTS_IGNORE:
136+
with self.subTest(f=f):
137+
self.assertEqual(process_changed_files({Path(f)}), Outputs())
138+
139+
def test_wasi_and_android(self):
140+
f = {Path(".github/workflows/reusable-wasi.yml"), Path("Android/comhad")}
141+
result = process_changed_files(f)
142+
self.assertTrue(result.run_tests)
143+
self.assertTrue(result.run_wasi)
144+
145+
146+
if __name__ == "__main__":
147+
unittest.main()

Tools/build/compute-changes.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,27 @@ def process_changed_files(changed_files: Set[Path]) -> Outputs:
225225

226226
if file.parent == GITHUB_WORKFLOWS_PATH:
227227
if file.name in ("build.yml", "reusable-cifuzz.yml"):
228-
run_tests = run_ci_fuzz = run_ci_fuzz_stdlib = True
228+
run_tests = run_ci_fuzz = run_ci_fuzz_stdlib = run_windows_tests = True
229229
has_platform_specific_change = False
230+
continue
230231
if file.name == "reusable-docs.yml":
231232
run_docs = True
233+
continue
234+
if file.name == "reusable-windows.yml":
235+
run_tests = True
236+
run_windows_tests = True
237+
continue
232238
if file.name == "reusable-windows-msi.yml":
233239
run_windows_msi = True
240+
continue
234241
if file.name == "reusable-macos.yml":
235242
run_tests = True
236243
platforms_changed.add("macos")
244+
continue
237245
if file.name == "reusable-wasi.yml":
238246
run_tests = True
239247
platforms_changed.add("wasi")
240-
continue
248+
continue
241249

242250
if not doc_file and file not in RUN_TESTS_IGNORE:
243251
run_tests = True

0 commit comments

Comments
 (0)