Skip to content

Commit 9b15d03

Browse files
committed
StdlibUnittest: don't pass the name of the executable on the command line
Also, add a test for the command line of the child process.
1 parent 24d2164 commit 9b15d03

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ public func runAllTests() {
786786
var filter: String? = nil
787787
var args = [String]()
788788
var i = 0
789+
i += 1 // Skip the name of the executable.
789790
while i < Process.arguments.count {
790791
let arg = Process.arguments[i]
791792
if arg == "--stdlib-unittest-in-process" {
@@ -810,8 +811,8 @@ public func runAllTests() {
810811
print(message)
811812
return
812813
}
813-
814-
// pass through arguments to the child process
814+
815+
// Pass through unparsed arguments to the child process.
815816
args.append(Process.arguments[i])
816817

817818
i += 1

test/1_stdlib/PrintFloat.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: %target-build-swift -c -force-single-frontend-invocation -parse-as-library -emit-module -emit-module-path %t/PrintTestTypes.swiftmodule -o %t/PrintTestTypes.o %S/Inputs/PrintTestTypes.swift
33
// RUN: %target-build-swift %s -Xlinker %t/PrintTestTypes.o -I %t -L %t -o %t/main.out
44
// RUN: %target-run %t/main.out
5-
// RUN: %target-run %t/main.out --env ru_RU.UTF-8
5+
// RUN: %target-run %t/main.out --locale ru_RU.UTF-8
66
// REQUIRES: executable_test
77
// XFAIL: linux
88

@@ -13,8 +13,8 @@ import PrintTestTypes
1313
let PrintTests = TestSuite("PrintFloat")
1414

1515
PrintTests.setUp {
16-
if Process.arguments.contains("--env") {
17-
let locale = Process.arguments[4]
16+
if let localeArgIndex = Process.arguments.indexOf("--locale") {
17+
let locale = Process.arguments[localeArgIndex + 1]
1818
expectEqual("ru_RU.UTF-8", locale)
1919
setlocale(LC_ALL, locale)
2020
} else {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: rm -rf %t && mkdir %t
2+
// RUN: %target-build-swift %s -o %t/main.out
3+
// RUN: %target-run %t/main.out | FileCheck -check-prefix=CHECK-EMPTY %s
4+
// RUN: %target-run %t/main.out --abc | FileCheck -check-prefix=CHECK-1 %s
5+
// RUN: %target-run %t/main.out --abc def | FileCheck -check-prefix=CHECK-2 %s
6+
// RUN: %target-run %t/main.out a --bcd efghijk | FileCheck -check-prefix=CHECK-3 %s
7+
// REQUIRES: executable_test
8+
9+
import StdlibUnittest
10+
11+
// Also import modules which are used by StdlibUnittest internally. This
12+
// workaround is needed to link all required libraries in case we compile
13+
// StdlibUnittest with -sil-serialize-all.
14+
#if _runtime(_ObjC)
15+
import ObjectiveC
16+
#endif
17+
18+
var CommandLineArguments = TestSuite("CommandLineArguments")
19+
CommandLineArguments.test("printCommandLineArguments") {
20+
debugPrint(Process.arguments)
21+
}
22+
// CHECK-EMPTY: {{^}}out>>> ["{{[^"]+}}", "--stdlib-unittest-run-child"]{{$}}
23+
// CHECK-1: {{^}}out>>> ["{{[^"]+}}", "--stdlib-unittest-run-child", "--abc"]{{$}}
24+
// CHECK-2: {{^}}out>>> ["{{[^"]+}}", "--stdlib-unittest-run-child", "--abc", "def"]{{$}}
25+
// CHECK-3: {{^}}out>>> ["{{[^"]+}}", "--stdlib-unittest-run-child", "a", "--bcd", "efghijk"]{{$}}
26+
27+
runAllTests()
28+

0 commit comments

Comments
 (0)