Skip to content

Commit 7abdab6

Browse files
committed
Convert ansible-test compile into a sanity test.
1 parent 0ce8d38 commit 7abdab6

File tree

13 files changed

+166
-198
lines changed

13 files changed

+166
-198
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Sanity Tests » compile
2+
======================
3+
4+
See :doc:`../../testing_compile` for more information.

docs/docsite/rst/dev_guide/testing_compile.rst

+9-7
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,36 @@ Compile tests check source files for valid syntax on all supported python versio
1515
- 3.5
1616
- 3.6
1717

18+
NOTE: In Ansible 2.4 and earlier the compile test was provided by a dedicated sub-command ``ansible-test compile`` instead of a sanity test using ``ansible-test sanity --test compile``.
19+
1820
Running compile tests locally
1921
=============================
2022

21-
Unit tests can be run across the whole code base by doing:
23+
Compile tests can be run across the whole code base by doing:
2224

2325
.. code:: shell
2426
2527
cd /path/to/ansible/source
2628
source hacking/env-setup
27-
ansible-test compile
29+
ansible-test sanity --test compile
2830
2931
Against a single file by doing:
3032

3133
.. code:: shell
3234
33-
ansible-test compile lineinfile
35+
ansible-test sanity --test compile lineinfile
3436
3537
Or against a specific Python version by doing:
3638

3739
.. code:: shell
3840
39-
ansible-test compile --python 2.7 lineinfile
41+
ansible-test sanity --test compile --python 2.7 lineinfile
4042
4143
For advanced usage see the help:
4244

4345
.. code:: shell
4446
45-
ansible-test units --help
47+
ansible-test sanity --help
4648
4749
4850
Installing dependencies
@@ -54,7 +56,7 @@ The dependencies can be installed using the ``--requirements`` argument. For exa
5456

5557
.. code:: shell
5658
57-
ansible-test units --requirements lineinfile
59+
ansible-test sanity --test compile --requirements lineinfile
5860
5961
6062
@@ -64,4 +66,4 @@ The full list of requirements can be found at `test/runner/requirements <https:/
6466
Extending compile tests
6567
=======================
6668

67-
If you believe changes are needed to the Compile tests please add a comment on the `Testing Working Group Agenda <https://github.com/ansible/community/blob/master/meetings/README.md>`_ so it can be discussed.
69+
If you believe changes are needed to the compile tests please add a comment on the `Testing Working Group Agenda <https://github.com/ansible/community/blob/master/meetings/README.md>`_ so it can be discussed.

shippable.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ matrix:
88
exclude:
99
- env: T=none
1010
include:
11-
- env: T=other
11+
- env: T=sanity/1
12+
- env: T=sanity/2
1213

1314
- env: T=units/2.6
1415
- env: T=units/2.7

test/runner/Makefile

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
.PHONY: all compile sanity units
1+
.PHONY: all sanity units
22

3-
all: compile sanity units
4-
5-
compile:
6-
./ansible-test compile test/runner/ ${TEST_FLAGS}
3+
all: sanity units
74

85
sanity:
96
./ansible-test sanity test/runner/ ${TEST_FLAGS}

test/runner/lib/classification.py

+25-12
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def categorize_changes(args, paths, verbose_command=None):
4444

4545
commands = {
4646
'sanity': set(),
47-
'compile': set(),
4847
'units': set(),
4948
'integration': set(),
5049
'windows-integration': set(),
@@ -128,7 +127,6 @@ def __init__(self, args):
128127
self.sanity_targets = list(walk_sanity_targets())
129128
self.powershell_targets = [t for t in self.sanity_targets if os.path.splitext(t.path)[1] == '.ps1']
130129

131-
self.compile_paths = set(t.path for t in self.compile_targets)
132130
self.units_modules = set(t.module for t in self.units_targets if t.module)
133131
self.units_paths = set(a for t in self.units_targets for a in t.aliases)
134132
self.sanity_paths = set(t.path for t in self.sanity_targets)
@@ -228,10 +226,6 @@ def classify(self, path):
228226
if result is None:
229227
return None
230228

231-
# compile path if eligible
232-
if path in self.compile_paths:
233-
result['compile'] = path
234-
235229
# run sanity on path unless result specified otherwise
236230
if path in self.sanity_paths and 'sanity' not in result:
237231
result['sanity'] = path
@@ -393,11 +387,6 @@ def _classify(self, path):
393387
if path.startswith('test/cache/'):
394388
return minimal
395389

396-
if path.startswith('test/compile/'):
397-
return {
398-
'compile': 'all',
399-
}
400-
401390
if path.startswith('test/results/'):
402391
return minimal
403392

@@ -544,7 +533,32 @@ def _classify(self, path):
544533

545534
return all_tests(self.args) # test infrastructure, run all tests
546535

536+
if path.startswith('test/utils/shippable/tools/'):
537+
return minimal # not used by tests
538+
547539
if path.startswith('test/utils/shippable/'):
540+
if dirname == 'test/utils/shippable':
541+
test_map = {
542+
'cloud.sh': 'integration:cloud/',
543+
'freebsd.sh': 'integration:all',
544+
'linux.sh': 'integration:all',
545+
'network.sh': 'network-integration:all',
546+
'osx.sh': 'integration:all',
547+
'rhel.sh': 'integration:all',
548+
'sanity.sh': 'sanity:all',
549+
'units.sh': 'units:all',
550+
'windows.sh': 'windows-integration:all',
551+
}
552+
553+
test_match = test_map.get(filename)
554+
555+
if test_match:
556+
test_command, test_target = test_match.split(':')
557+
558+
return {
559+
test_command: test_target,
560+
}
561+
548562
return all_tests(self.args) # test infrastructure, run all tests
549563

550564
if path.startswith('test/utils/'):
@@ -602,7 +616,6 @@ def all_tests(args, force=False):
602616

603617
return {
604618
'sanity': 'all',
605-
'compile': 'all',
606619
'units': 'all',
607620
'integration': integration_all_target,
608621
'windows-integration': integration_all_target,

test/runner/lib/config.py

-9
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,6 @@ def __init__(self, args):
206206
self.collect_only = args.collect_only # type: bool
207207

208208

209-
class CompileConfig(TestConfig):
210-
"""Configuration for the compile command."""
211-
def __init__(self, args):
212-
"""
213-
:type args: any
214-
"""
215-
super(CompileConfig, self).__init__(args, 'compile')
216-
217-
218209
class CoverageConfig(EnvironmentConfig):
219210
"""Configuration for the coverage command."""
220211
def __init__(self, args):

test/runner/lib/executor.py

-119
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
walk_network_integration_targets,
6464
walk_windows_integration_targets,
6565
walk_units_targets,
66-
walk_compile_targets,
6766
)
6867

6968
from lib.changes import (
@@ -82,7 +81,6 @@
8281
from lib.config import (
8382
TestConfig,
8483
EnvironmentConfig,
85-
CompileConfig,
8684
IntegrationConfig,
8785
NetworkIntegrationConfig,
8886
PosixIntegrationConfig,
@@ -91,13 +89,6 @@
9189
WindowsIntegrationConfig,
9290
)
9391

94-
from lib.test import (
95-
TestMessage,
96-
TestSuccess,
97-
TestFailure,
98-
TestSkipped,
99-
)
100-
10192
SUPPORTED_PYTHON_VERSIONS = (
10293
'2.6',
10394
'2.7',
@@ -106,8 +97,6 @@
10697
'3.7',
10798
)
10899

109-
COMPILE_PYTHON_VERSIONS = SUPPORTED_PYTHON_VERSIONS
110-
111100

112101
def check_startup():
113102
"""Checks to perform at startup before running commands."""
@@ -1024,114 +1013,6 @@ def command_units(args):
10241013
raise
10251014

10261015

1027-
def command_compile(args):
1028-
"""
1029-
:type args: CompileConfig
1030-
"""
1031-
changes = get_changes_filter(args)
1032-
require = (args.require or []) + changes
1033-
include, exclude = walk_external_targets(walk_compile_targets(), args.include, args.exclude, require)
1034-
1035-
if not include:
1036-
raise AllTargetsSkipped()
1037-
1038-
if args.delegate:
1039-
raise Delegate(require=changes)
1040-
1041-
install_command_requirements(args)
1042-
1043-
total = 0
1044-
failed = []
1045-
1046-
for version in COMPILE_PYTHON_VERSIONS:
1047-
# run all versions unless version given, in which case run only that version
1048-
if args.python and version != args.python_version:
1049-
continue
1050-
1051-
display.info('Compile with Python %s' % version)
1052-
1053-
result = compile_version(args, version, include, exclude)
1054-
result.write(args)
1055-
1056-
total += 1
1057-
1058-
if isinstance(result, TestFailure):
1059-
failed.append('compile --python %s' % version)
1060-
1061-
if failed:
1062-
message = 'The %d compile test(s) listed below (out of %d) failed. See error output above for details.\n%s' % (
1063-
len(failed), total, '\n'.join(failed))
1064-
1065-
if args.failure_ok:
1066-
display.error(message)
1067-
else:
1068-
raise ApplicationError(message)
1069-
1070-
1071-
def compile_version(args, python_version, include, exclude):
1072-
"""
1073-
:type args: CompileConfig
1074-
:type python_version: str
1075-
:type include: tuple[CompletionTarget]
1076-
:type exclude: tuple[CompletionTarget]
1077-
:rtype: TestResult
1078-
"""
1079-
command = 'compile'
1080-
test = ''
1081-
1082-
# optional list of regex patterns to exclude from tests
1083-
skip_file = 'test/compile/python%s-skip.txt' % python_version
1084-
1085-
if os.path.exists(skip_file):
1086-
with open(skip_file, 'r') as skip_fd:
1087-
skip_paths = skip_fd.read().splitlines()
1088-
else:
1089-
skip_paths = []
1090-
1091-
# augment file exclusions
1092-
skip_paths += [e.path for e in exclude]
1093-
1094-
skip_paths = sorted(skip_paths)
1095-
1096-
python = 'python%s' % python_version
1097-
cmd = [python, 'test/compile/compile.py']
1098-
1099-
if skip_paths:
1100-
cmd += ['-x', '|'.join(skip_paths)]
1101-
1102-
cmd += [target.path if target.path == '.' else './%s' % target.path for target in include]
1103-
1104-
try:
1105-
stdout, stderr = run_command(args, cmd, capture=True)
1106-
status = 0
1107-
except SubprocessError as ex:
1108-
stdout = ex.stdout
1109-
stderr = ex.stderr
1110-
status = ex.status
1111-
1112-
if stderr:
1113-
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
1114-
1115-
if args.explain:
1116-
return TestSkipped(command, test, python_version=python_version)
1117-
1118-
pattern = r'^(?P<path>[^:]*):(?P<line>[0-9]+):(?P<column>[0-9]+): (?P<message>.*)$'
1119-
1120-
results = [re.search(pattern, line).groupdict() for line in stdout.splitlines()]
1121-
1122-
results = [TestMessage(
1123-
message=r['message'],
1124-
path=r['path'].replace('./', ''),
1125-
line=int(r['line']),
1126-
column=int(r['column']),
1127-
) for r in results]
1128-
1129-
if results:
1130-
return TestFailure(command, test, messages=results, python_version=python_version)
1131-
1132-
return TestSuccess(command, test, python_version=python_version)
1133-
1134-
11351016
def get_changes_filter(args):
11361017
"""
11371018
:type args: TestConfig

0 commit comments

Comments
 (0)