Files
swift-mirror/utils/build_swift/tests/test_migration.py
Ross Bayer 4edb8d9baa [build-script] Presets Module (#14422)
* Implemented a presets module which includes a more robust and easy to understand parser. Moved the swift-sdks migration code to a new migration module and added testing for both the presets and migration modules. Also converted build-script to use the new presets parser.

* Switched the expansion algorithm to resolve mixins in-place (little known feature) and also changed the parser to skip all non-preset sections. Tests are included for these two behaviors.

* Re-worked the presets error hierarchy to have more descriptive and information packed exception classes. Also re-worked the PresetParser to catch duplicate preset declarations and duplicate options in a single preset. There's some special shim-code to handle the disconnect between the Python 2 ConfigParser module and the Python 3 update which adds DuplicateOptionError.
2018-02-26 11:26:22 -08:00

72 lines
2.2 KiB
Python

# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
from __future__ import absolute_import, unicode_literals
from .utils import TestCase, add_metaclass
from .. import migration
def _get_sdk_targets(sdk_names):
targets = []
for sdk_name in sdk_names:
targets += migration._SDK_TARGETS[sdk_name]
return targets
def _get_sdk_target_names(sdk_names):
return [target.name for target in _get_sdk_targets(sdk_names)]
# -----------------------------------------------------------------------------
class TestMigrateSwiftSDKsMeta(type):
"""Metaclass used to dynamically generate test methods.
"""
def __new__(cls, name, bases, attrs):
# Generate tests for migrating each Swift SDK
for sdk_name in migration._SDK_TARGETS.keys():
test_name = 'test_migrate_swift_sdk_' + sdk_name
attrs[test_name] = cls.generate_migrate_swift_sdks_test(sdk_name)
return super(TestMigrateSwiftSDKsMeta, cls).__new__(
cls, name, bases, attrs)
@classmethod
def generate_migrate_swift_sdks_test(cls, sdk_name):
def test(self):
args = ['--swift-sdks={}'.format(sdk_name)]
args = migration.migrate_swift_sdks(args)
target_names = _get_sdk_target_names([sdk_name])
self.assertListEqual(args, [
'--stdlib-deployment-targets={}'.format(' '.join(target_names))
])
return test
@add_metaclass(TestMigrateSwiftSDKsMeta)
class TestMigrateSwiftSDKs(TestCase):
def test_multiple_swift_sdk_flags(self):
args = [
'--swift-sdks=OSX',
'--swift-sdks=OSX;IOS;IOS_SIMULATOR'
]
args = migration.migrate_swift_sdks(args)
target_names = _get_sdk_target_names(['OSX', 'IOS', 'IOS_SIMULATOR'])
self.assertListEqual(args, [
'--stdlib-deployment-targets={}'.format(' '.join(target_names))
])