Skip to content

Commit d9f6baf

Browse files
committed
gh-115421: Test that our Makefile has all needed test folders
1 parent 7bc7937 commit d9f6baf

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
Tests for `Makefile`.
3+
"""
4+
5+
import os
6+
import unittest
7+
from test import support
8+
9+
MAKEFILE = os.path.join(support.REPO_ROOT, 'Makefile')
10+
11+
if not support.check_impl_detail(cpython=True):
12+
raise unittest.SkipTest('cpython only')
13+
if support.MS_WINDOWS:
14+
raise unittest.SkipTest('Windows does not support make')
15+
if not os.path.exists(MAKEFILE) or not os.path.isfile(MAKEFILE):
16+
raise unittest.SkipTest(f'{tool} directory could not be found')
17+
18+
try:
19+
import _testcapi
20+
except ImportError:
21+
TEST_MODULES = False
22+
else:
23+
TEST_MODULES = True
24+
25+
@support.requires_subprocess()
26+
class TestMakefile(unittest.TestCase):
27+
def list_test_dirs(self):
28+
import subprocess
29+
return subprocess.check_output(
30+
['make', '-C', support.REPO_ROOT, 'listtestmodules'],
31+
universal_newlines=True,
32+
encoding='utf-8',
33+
)
34+
35+
def check_existing_test_modules(self, result):
36+
test_dirs = result.split(' ')
37+
unique_test_dirs = set(test_dirs)
38+
self.assertEqual(len(test_dirs), len(unique_test_dirs))
39+
40+
idle_test = 'idlelib/idle_test'
41+
self.assertIn(idle_test, test_dirs)
42+
43+
used = [idle_test]
44+
for dirpath, _, _ in os.walk(support.TEST_HOME_DIR):
45+
dirname = os.path.basename(dirpath)
46+
if dirname == '__pycache__':
47+
continue
48+
with self.subTest(dirpath=dirpath):
49+
relpath = os.path.relpath(dirpath, support.STDLIB_DIR)
50+
self.assertIn(relpath, test_dirs)
51+
used.append(relpath)
52+
53+
# Check that there are no extra entries:
54+
self.assertEqual(
55+
unique_test_dirs.symmetric_difference(set(used)),
56+
set(),
57+
)
58+
59+
def check_missing_test_modules(self, result):
60+
self.assertEqual(result, '')
61+
62+
def test_makefile_test_folders(self):
63+
result = self.list_test_dirs().strip()
64+
if TEST_MODULES:
65+
self.check_existing_test_modules(result)
66+
else:
67+
self.check_missing_test_modules(result)

Makefile.pre.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,12 @@ COMPILEALL_OPTS=-j0
23732373

23742374
TEST_MODULES=@TEST_MODULES@
23752375

2376+
.PHONY: listtestmodules
2377+
listtestmodules:
2378+
@if test "$(TEST_MODULES)" = yes; then \
2379+
echo "$(TESTSUBDIRS)"; \
2380+
fi
2381+
23762382
.PHONY: libinstall
23772383
libinstall: all $(srcdir)/Modules/xxmodule.c
23782384
@for i in $(SCRIPTDIR) $(LIBDEST); \

0 commit comments

Comments
 (0)