Rewrite generate-xcfilelists in Python
[WebKit-https.git] / Tools / Scripts / webkitpy / xcode / sdk_unittest.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright (C) 2019 Apple Inc.  All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # 1. Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 #    notice, this list of conditions and the following disclaimer in the
14 #    documentation and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
17 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
20 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 import unittest
29
30 import webkitpy.xcode.sdk as sdk
31 from webkitpy.common.system.executive_mock import MockExecutive2
32
33
34 class SDKTest(unittest.TestCase):
35
36     TEST_XCODEBUILD_SHOWSDKS_OUTPUT = """\
37         iOS SDKs:
38         \tiOS 12.0                      \t-sdk iphoneos12.0
39         \tiOS 12.0 Internal             \t-sdk iphoneos12.0.internal
40
41         iOS Simulator SDKs:
42         \tSimulator - iOS 12.0          \t-sdk iphonesimulator12.0
43
44         macOS SDKs:
45         \tmacOS 10.13                   \t-sdk macosx10.13
46         \tmacOS 10.13 Internal          \t-sdk macosx10.13internal
47         \tmacOS 10.14                   \t-sdk macosx10.14
48         \tmacOS 10.14 Internal          \t-sdk macosx10.14internal
49
50         tvOS SDKs:
51         \ttvOS 12.0                     \t-sdk appletvos12.0
52         \ttvOS 12.0 Internal            \t-sdk appletvos12.0.internal
53
54         tvOS Simulator SDKs:
55         \tSimulator - tvOS 12.0         \t-sdk appletvsimulator12.0
56
57         watchOS SDKs:
58         \twatchOS 4.0                   \t-sdk watchos4.0
59         \twatchOS 4.0 Internal          \t-sdk watchos4.0.internal
60
61         watchOS Simulator SDKs:
62         \tSimulator - watchOS 4.0       \t-sdk watchsimulator4.0
63         """
64
65     @classmethod
66     def setUpClass(cls):
67         cls.executive = MockExecutive2(output=cls.TEST_XCODEBUILD_SHOWSDKS_OUTPUT)
68
69     @classmethod
70     def tearDownClass(cls):
71         cls.executive = None
72
73     def test_iphoneos(self):
74         preferred_sdk = sdk.SDK.get_preferred_sdk_for_platform("iphoneos", self.executive)
75         self.assertEquals("iphoneos", preferred_sdk.platform)
76         self.assertEquals("12.0", preferred_sdk.version)
77         self.assertTrue(preferred_sdk.internal)
78
79     def test_iphonesim(self):
80         preferred_sdk = sdk.SDK.get_preferred_sdk_for_platform("iphonesimulator", self.executive)
81         self.assertEquals("iphonesimulator", preferred_sdk.platform)
82         self.assertEquals("12.0", preferred_sdk.version)
83         self.assertFalse(preferred_sdk.internal)
84
85     def test_macos(self):
86         preferred_sdk = sdk.SDK.get_preferred_sdk_for_platform("macosx", self.executive)
87         self.assertEquals("macosx", preferred_sdk.platform)
88         self.assertEquals("10.14", preferred_sdk.version)
89         self.assertTrue(preferred_sdk.internal)
90
91     def test_appletvos(self):
92         preferred_sdk = sdk.SDK.get_preferred_sdk_for_platform("appletvos", self.executive)
93         self.assertEquals("appletvos", preferred_sdk.platform)
94         self.assertEquals("12.0", preferred_sdk.version)
95         self.assertTrue(preferred_sdk.internal)
96
97     def test_appletvsim(self):
98         preferred_sdk = sdk.SDK.get_preferred_sdk_for_platform("appletvsimulator", self.executive)
99         self.assertEquals("appletvsimulator", preferred_sdk.platform)
100         self.assertEquals("12.0", preferred_sdk.version)
101         self.assertFalse(preferred_sdk.internal)
102
103     def test_watchos(self):
104         preferred_sdk = sdk.SDK.get_preferred_sdk_for_platform("watchos", self.executive)
105         self.assertEquals("watchos", preferred_sdk.platform)
106         self.assertEquals("4.0", preferred_sdk.version)
107         self.assertTrue(preferred_sdk.internal)
108
109     def test_watchsimulator(self):
110         preferred_sdk = sdk.SDK.get_preferred_sdk_for_platform("watchsimulator", self.executive)
111         self.assertEquals("watchsimulator", preferred_sdk.platform)
112         self.assertEquals("4.0", preferred_sdk.version)
113         self.assertFalse(preferred_sdk.internal)
114
115     def test_prodos(self):
116         preferred_sdk = sdk.SDK.get_preferred_sdk_for_platform("prodos", self.executive)
117         self.assertEquals("prodos", preferred_sdk.platform)
118         self.assertEquals(None, preferred_sdk.version)
119         self.assertEquals(None, preferred_sdk.internal)