Skip to content

Commit 1fcd7d7

Browse files
authored
[test] Add '--param swift-version=3' to lit's configuration. (swiftlang#5566)
This allows us to run our entire test suite (well, okay, just invocations of swift/swiftc and swift-ide-test) under Swift 3 mode or Swift 4 mode, which will be more important as the two modes diverge. The default is Swift 3 mode for now, which matches the behavior before this patch (because the master compiler still calls itself 3.0). Individual tests can still use "-swift-version 3" to override the mode set by lit, but if an entire test requires Swift 3 or Swift 4, there's also a new test feature "SWIFT_VERSION=3" or "SWIFT_VERSION=4". However, if you /do/ need to override or restrict the version, you should also add a test for the "other" version as well, unless it's part of the Compatibility suite or otherwise specifically testing -swift-version-related functionality.
1 parent bfab9d6 commit 1fcd7d7

File tree

6 files changed

+61
-9
lines changed

6 files changed

+61
-9
lines changed

docs/Testing.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@ targets mentioned above and modify it as necessary. lit.py also has several
150150
useful features, like timing tests and providing a timeout. Check these features
151151
out with ``lit.py -h``.
152152

153+
Extra lit.py invocation options
154+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155+
156+
* ``--param gmalloc`` will run all tests under Guard Malloc (macOS only). See
157+
``man libgmalloc`` for more information.
158+
159+
* ``--param swift-version=<MAJOR>`` overrides the default Swift language
160+
version used by swift/swiftc and swift-ide-test.
161+
162+
* ``--param interpret`` is an experimental option for running execution tests
163+
using Swift's interpreter rather than compiling them first. Note that this
164+
does not affect all substitutions.
165+
166+
* ``--param swift_test_mode=<MODE>`` drives the various suffix variations
167+
mentioned above. Again, it's best to get the invocation from the existing
168+
build system targets and modify it rather than constructing it yourself.
169+
153170
Writing tests
154171
-------------
155172

@@ -422,6 +439,10 @@ FIXME: full list.
422439

423440
* ``optimized_stdlib_<CPUNAME>``: an optimized stdlib plus cpu configuration.
424441

442+
* ``SWIFT_VERSION=<MAJOR>``: restricts a test to Swift 3 or Swift 4. If you
443+
need to use this, make sure to add a test for the other version as well
444+
unless you are specifically testing ``-swift-version``-related functionality.
445+
425446
* ``XFAIL: linux``: tests that need to be adapted for Linux, for example parts
426447
that depend on Objective-C interop need to be split out.
427448

test/ClangModules/invalid_bridging_header.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %target-swift-frontend-parse -import-objc-header %S/Inputs/invalid_bridging_header.h %s > %t.out 2>&1
1+
// RUN: not %target-swift-frontend -parse -import-objc-header %S/Inputs/invalid_bridging_header.h %s > %t.out 2>&1
22
// RUN: %FileCheck %s < %t.out
33

44
// REQUIRES: objc_interop

test/Compatibility/attr_escaping.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-parse-verify-swift
2+
// REQUIRES: SWIFT_VERSION=3
23

34
// This is allowed, in order to keep source compat with Swift version 3.0.
45
func takesVarargsOfFunctionsExplicitEscaping(_ fns: @escaping () -> ()...) {}

test/Compatibility/protocol_composition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: rm -rf %t && mkdir -p %t
22
// RUN: %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -parse -primary-file %t/swift3.swift %t/common.swift -verify
3+
// RUN: %target-swift-frontend -parse -primary-file %t/swift3.swift %t/common.swift -verify -swift-version 3
44
// RUN: %target-swift-frontend -parse -primary-file %t/swift4.swift %t/common.swift -verify -swift-version 4
55

66
// BEGIN common.swift
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %swiftc_driver_plain -parse -Xfrontend -verify %s
2+
3+
// This test should be updated to match the expected default Swift version
4+
// when swiftc is invoked directly.
5+
// It should /not/ follow the version specified when invoking lit.
6+
7+
#if swift(>=3)
8+
asdf // expected-error {{use of unresolved identifier}}
9+
#else
10+
jkl
11+
#endif
12+
13+
#if swift(>=4)
14+
aoeu
15+
#else
16+
htn // expected-error {{use of unresolved identifier}}
17+
#endif

test/lit.cfg

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,18 @@ if test_sdk_overlay_dir is not None:
323323
lit_config.note('Using SDK overlay dir: ' + test_sdk_overlay_dir)
324324
resource_dir_opt += (" %s" % sdk_overlay_dir_opt)
325325

326+
# Default to Swift 3 for now.
327+
# Note that this accepts both `--param swift-version` (like the compiler flag)
328+
# and `--param swift_version` (like a lit configuration parameter).
329+
swift_version = lit_config.params.get('swift-version',
330+
lit_config.params.get('swift_version', '3'))
331+
lit_config.note('Compiling with -swift-version ' + swift_version)
332+
config.swift_test_options = '-swift-version ' + swift_version
333+
326334
test_options = os.environ.get('SWIFT_TEST_OPTIONS')
327-
config.swift_test_options = ' ' + test_options if test_options else ''
335+
if test_options:
336+
config.swift_test_options += ' '
337+
config.swift_test_options += test_options
328338

329339
clang_module_cache_path = tempfile.mkdtemp(prefix="swift-testsuite-clang-module-cache")
330340
mcp_opt = "-module-cache-path %r" % clang_module_cache_path
@@ -341,22 +351,23 @@ config.substitutions.append( ('%{python}', sys.executable) )
341351
config.substitutions.append( ('%mcp_opt', mcp_opt) )
342352
config.substitutions.append( ('%swift_driver_plain', "%r" % config.swift) )
343353
config.substitutions.append( ('%swiftc_driver_plain', "%r" % config.swiftc) )
344-
config.substitutions.append( ('%swift_driver', "env SDKROOT= %r %s%s" % (config.swift, mcp_opt, config.swift_test_options)) )
345-
config.substitutions.append( ('%swiftc_driver', "env SDKROOT= %r %s%s" % (config.swiftc, mcp_opt, config.swift_test_options)) )
354+
config.substitutions.append( ('%swift_driver', "env SDKROOT= %r %s %s" % (config.swift, mcp_opt, config.swift_test_options)) )
355+
config.substitutions.append( ('%swiftc_driver', "env SDKROOT= %r %s %s" % (config.swiftc, mcp_opt, config.swift_test_options)) )
346356
config.substitutions.append( ('%sil-opt', "%r %s" % (config.sil_opt, mcp_opt)) )
347357
config.substitutions.append( ('%sil-extract', "%r %s" % (config.sil_extract, mcp_opt)) )
348358
config.substitutions.append( ('%lldb-moduleimport-test', "%r %s" % (config.lldb_moduleimport_test, mcp_opt)) )
349359
config.substitutions.append( ('%swift-ide-test_plain', config.swift_ide_test) )
350-
config.substitutions.append( ('%swift-ide-test', "%r %s %s" % (config.swift_ide_test, mcp_opt, ccp_opt)) )
360+
config.substitutions.append( ('%swift-ide-test', "%r %s %s -swift-version %s" % (config.swift_ide_test, mcp_opt, ccp_opt, swift_version)) )
351361
config.substitutions.append( ('%swift-format', config.swift_format) )
352362
config.substitutions.append( ('%llvm-link', config.llvm_link) )
353363
config.substitutions.append( ('%swift-llvm-opt', config.swift_llvm_opt) )
354364
config.substitutions.append( ('%llvm-dwarfdump', config.llvm_dwarfdump) )
355365

356366
# This must come after all substitutions containing "%swift".
357367
config.substitutions.append(
358-
('%swift', "%r -frontend %s -disable-objc-attr-requires-foundation-module%s"
359-
% (config.swift, mcp_opt, config.swift_test_options)) )
368+
('%swift',
369+
"%r -frontend %s -disable-objc-attr-requires-foundation-module %s"
370+
% (config.swift, mcp_opt, config.swift_test_options)) )
360371

361372
config.clang_include_dir = \
362373
os.path.join(os.path.dirname(os.path.dirname(config.swift)), 'include')
@@ -443,6 +454,8 @@ config.available_features.add("PTRSIZE=" + run_ptrsize)
443454
if run_cpu == "i386" or run_cpu == "x86_64":
444455
config.available_features.add("CPU=i386_or_x86_64")
445456

457+
config.available_features.add("SWIFT_VERSION=" + swift_version)
458+
446459
if "optimized_stdlib" in config.available_features:
447460
config.available_features.add("optimized_stdlib_" + run_cpu)
448461

@@ -736,7 +749,7 @@ elif run_os in ['linux-gnu', 'linux-gnueabihf', 'freebsd', 'windows-cygnus', 'wi
736749
config.target_run = ''
737750
if 'interpret' in lit_config.params:
738751
target_run_base = (
739-
'%s -target %s %s %s -module-name main%s %s'
752+
'%s -target %s %s %s -module-name main %s %s'
740753
% (config.swift, config.variant_triple, resource_dir_opt,
741754
mcp_opt, config.swift_test_options,
742755
swift_execution_tests_extra_flags))

0 commit comments

Comments
 (0)