1# Copyright 2017 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import unittest
6import compile_xcassets
7
8
9class TestFilterCompilerOutput(unittest.TestCase):
10
11  relative_paths = {
12    '/Users/janedoe/chromium/src/Chromium.xcassets':
13        '../../Chromium.xcassets',
14    '/Users/janedoe/chromium/src/out/Default/Chromium.app/Assets.car':
15        'Chromium.app/Assets.car',
16  }
17
18  def testNoError(self):
19    self.assertEquals(
20        '',
21        compile_xcassets.FilterCompilerOutput(
22            '/* com.apple.actool.compilation-results */\n'
23            '/Users/janedoe/chromium/src/out/Default/Chromium.app/Assets.car\n',
24            self.relative_paths))
25
26  def testNoErrorRandomMessages(self):
27    self.assertEquals(
28        '',
29        compile_xcassets.FilterCompilerOutput(
30            '2017-07-04 04:59:19.460 ibtoold[23487:41214] CoreSimulator is att'
31                'empting to unload a stale CoreSimulatorService job.  Existing'
32                ' job (com.apple.CoreSimulator.CoreSimulatorService.179.1.E8tt'
33                'yeDeVgWK) is from an older version and is being removed to pr'
34                'event problems.\n'
35            '/* com.apple.actool.compilation-results */\n'
36            '/Users/janedoe/chromium/src/out/Default/Chromium.app/Assets.car\n',
37            self.relative_paths))
38
39  def testWarning(self):
40    self.assertEquals(
41        '/* com.apple.actool.document.warnings */\n'
42        '../../Chromium.xcassets:./image1.imageset/[universal][][][1x][][][]['
43            '][][]: warning: The file "image1.png" for the image set "image1"'
44            ' does not exist.\n',
45        compile_xcassets.FilterCompilerOutput(
46            '/* com.apple.actool.document.warnings */\n'
47            '/Users/janedoe/chromium/src/Chromium.xcassets:./image1.imageset/['
48                'universal][][][1x][][][][][][]: warning: The file "image1.png'
49                '" for the image set "image1" does not exist.\n'
50            '/* com.apple.actool.compilation-results */\n'
51            '/Users/janedoe/chromium/src/out/Default/Chromium.app/Assets.car\n',
52            self.relative_paths))
53
54  def testError(self):
55    self.assertEquals(
56        '/* com.apple.actool.errors */\n'
57        '../../Chromium.xcassets: error: The output directory "/Users/janedoe/'
58            'chromium/src/out/Default/Chromium.app" does not exist.\n',
59        compile_xcassets.FilterCompilerOutput(
60            '/* com.apple.actool.errors */\n'
61            '/Users/janedoe/chromium/src/Chromium.xcassets: error: The output '
62                'directory "/Users/janedoe/chromium/src/out/Default/Chromium.a'
63                'pp" does not exist.\n'
64            '/* com.apple.actool.compilation-results */\n',
65            self.relative_paths))
66
67  def testSpurious(self):
68    self.assertEquals(
69        '/* com.apple.actool.document.warnings */\n'
70        '../../Chromium.xcassets:./AppIcon.appiconset: warning: A 1024x1024 ap'
71            'p store icon is required for iOS apps\n',
72        compile_xcassets.FilterCompilerOutput(
73            '/* com.apple.actool.document.warnings */\n'
74            '/Users/janedoe/chromium/src/Chromium.xcassets:./AppIcon.appiconse'
75                't: warning: A 1024x1024 app store icon is required for iOS ap'
76                'ps\n'
77            '/* com.apple.actool.document.notices */\n'
78            '/Users/janedoe/chromium/src/Chromium.xcassets:./AppIcon.appiconse'
79                't/[][ipad][76x76][][][1x][][]: notice: (null)\n',
80            self.relative_paths))
81
82  def testComplexError(self):
83    self.assertEquals(
84        '/* com.apple.actool.errors */\n'
85        ': error: Failed to find a suitable device for the type SimDeviceType '
86            ': com.apple.dt.Xcode.IBSimDeviceType.iPad-2x with runtime SimRunt'
87            'ime : 10.3.1 (14E8301) - com.apple.CoreSimulator.SimRuntime.iOS-1'
88            '0-3\n'
89        '    Failure Reason: Failed to create SimDeviceSet at path /Users/jane'
90            'doe/Library/Developer/Xcode/UserData/IB Support/Simulator Devices'
91            '. You\'ll want to check the logs in ~/Library/Logs/CoreSimulator '
92            'to see why creating the SimDeviceSet failed.\n'
93        '    Underlying Errors:\n'
94        '        Description: Failed to initialize simulator device set.\n'
95        '        Failure Reason: Failed to subscribe to notifications from Cor'
96            'eSimulatorService.\n'
97        '        Underlying Errors:\n'
98        '            Description: Error returned in reply to notification requ'
99            'est: Connection invalid\n'
100        '            Failure Reason: Software caused connection abort\n',
101        compile_xcassets.FilterCompilerOutput(
102            '2017-07-07 10:37:27.367 ibtoold[88538:12553239] CoreSimulator det'
103                'ected Xcode.app relocation or CoreSimulatorService version ch'
104                'ange.  Framework path (/Applications/Xcode.app/Contents/Devel'
105                'oper/Library/PrivateFrameworks/CoreSimulator.framework) and v'
106                'ersion (375.21) does not match existing job path (/Library/De'
107                'veloper/PrivateFrameworks/CoreSimulator.framework/Versions/A/'
108                'XPCServices/com.apple.CoreSimulator.CoreSimulatorService.xpc)'
109                ' and version (459.13).  Attempting to remove the stale servic'
110                'e in order to add the expected version.\n'
111            '2017-07-07 10:37:27.625 ibtoold[88538:12553256] CoreSimulatorServ'
112                'ice connection interrupted.  Resubscribing to notifications.\n'
113            '2017-07-07 10:37:27.632 ibtoold[88538:12553264] CoreSimulatorServ'
114                'ice connection became invalid.  Simulator services will no lo'
115                'nger be available.\n'
116            '2017-07-07 10:37:27.642 ibtoold[88538:12553274] CoreSimulatorServ'
117                'ice connection became invalid.  Simulator services will no lo'
118                'nger be available.\n'
119            '/* com.apple.actool.errors */\n'
120            ': error: Failed to find a suitable device for the type SimDeviceT'
121                'ype : com.apple.dt.Xcode.IBSimDeviceType.iPad-2x with runtime'
122                ' SimRuntime : 10.3.1 (14E8301) - com.apple.CoreSimulator.SimR'
123                'untime.iOS-10-3\n'
124            '    Failure Reason: Failed to create SimDeviceSet at path /Users/'
125                'janedoe/Library/Developer/Xcode/UserData/IB Support/Simulator'
126                ' Devices. You\'ll want to check the logs in ~/Library/Logs/Co'
127                'reSimulator to see why creating the SimDeviceSet failed.\n'
128            '    Underlying Errors:\n'
129            '        Description: Failed to initialize simulator device set.\n'
130            '        Failure Reason: Failed to subscribe to notifications from'
131                ' CoreSimulatorService.\n'
132            '        Underlying Errors:\n'
133            '            Description: Error returned in reply to notification '
134                'request: Connection invalid\n'
135            '            Failure Reason: Software caused connection abort\n'
136            '/* com.apple.actool.compilation-results */\n',
137            self.relative_paths))
138
139
140if __name__ == '__main__':
141  unittest.main()
142