Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit dff05ca

Browse files
kazkjhoffner
authored andcommitted
Fix Swift compatibility issue around XCTMain (#465)
* Fix Swift compatibility issue around XCTMain
1 parent 40d3e27 commit dff05ca

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

lib/runners/swift.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports.run = function run(opts, cb) {
5252
args.push('/workspace/setup.swift');
5353
}
5454
fs.writeFileSync('/workspace/solution.swift', opts.solution);
55-
fs.writeFileSync('/workspace/main.swift', opts.fixture);
55+
fs.writeFileSync('/workspace/main.swift', opts.fixture.replace(/^\s*XCTMain\s*\(/m, '_XCTMain('));
5656
args.push('/workspace/solution.swift', '/workspace/main.swift');
5757

5858
return exec(args.join(' '), (err, stdout, stderr) => {

test/runners/swift_spec.js

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('swift runner', function() {
7373
}
7474
}
7575
76-
_XCTMain([
76+
XCTMain([
7777
testCase(CalculatorTest.allTests)
7878
])
7979
`,
@@ -87,6 +87,41 @@ describe('swift runner', function() {
8787
});
8888
});
8989

90+
it('should allow whitespace in "XCTMain ("', function(done) {
91+
var code = `
92+
func add(_ a: Int, _ b: Int) -> Int {
93+
return a + b
94+
}
95+
`;
96+
runner.run({
97+
language: 'swift',
98+
languageVersion: '3',
99+
code: code,
100+
fixture: `
101+
import XCTest
102+
class AddTest: XCTestCase {
103+
static var allTests = [
104+
("testAddCheck", testAddCheck),
105+
]
106+
func testAddCheck() {
107+
XCTAssertEqual(add(1, 1), 2, "add(1, 1) should be 2")
108+
}
109+
}
110+
111+
XCTMain ([
112+
testCase(AddTest.allTests)
113+
])
114+
`,
115+
testFramework: 'xctest'
116+
}, function(buffer) {
117+
expect(buffer.stdout).to.contain('<DESCRIBE::>AddTest');
118+
expect(buffer.stdout).to.contain('<IT::>testAddCheck');
119+
expect(buffer.stdout).to.contain('<PASSED::>Test Passed');
120+
expect(buffer.stdout).to.contain('<COMPLETEDIN::>');
121+
done();
122+
});
123+
});
124+
90125
it('should replace newlines in error messages with <:LF:>', function(done) {
91126
var code = `
92127
class Calculator {
@@ -113,7 +148,7 @@ describe('swift runner', function() {
113148
}
114149
}
115150
116-
_XCTMain([
151+
XCTMain([
117152
testCase(CalculatorTest.allTests)
118153
])
119154
`,
@@ -174,7 +209,7 @@ describe('swift runner', function() {
174209
}
175210
}
176211
177-
_XCTMain([
212+
XCTMain([
178213
testCase(CalculatorTest.allTests)
179214
])
180215
`,
@@ -227,7 +262,7 @@ describe('swift runner', function() {
227262
}
228263
}
229264
230-
_XCTMain([
265+
XCTMain([
231266
testCase(CalculatorTest.allTests)
232267
])
233268
`,
@@ -274,7 +309,7 @@ describe('swift runner', function() {
274309
}
275310
}
276311
277-
_XCTMain([
312+
XCTMain([
278313
testCase(GreetingsTest.allTests)
279314
])
280315
`,
@@ -332,7 +367,7 @@ describe('swift runner', function() {
332367
}
333368
}
334369
335-
_XCTMain([
370+
XCTMain([
336371
testCase(CalculatorTest.allTests),
337372
testCase(PersonTest.allTests),
338373
])

0 commit comments

Comments
 (0)