Skip to content

Commit e780555

Browse files
authored
Merge pull request #146 from swiftlang/jgrynspan/basic-swift-testing
Add basic integration tests for Swift Testing.
2 parents 5463f43 + 7da702b commit e780555

File tree

4 files changed

+75
-22
lines changed

4 files changed

+75
-22
lines changed

README.md

+15-14
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@ Tests
2121

2222
Here is a partial list of tests in the repository:
2323

24-
| Test Name | Functionality |
25-
|--------------------------|------------------------------------------------------------------|
26-
| basic | Check output of `swift --version` |
27-
| example-package-dealer | Build the example package-dealer package |
28-
| repl | Various REPL sanity checks, notably importing Darwin and Glibc |
29-
| swift-build-self-host | Use swift build to build itself |
30-
| swift-compiler | Compile a basic swift file |
31-
| test-c-library-swiftpm | Build a package that links a 3rd party library |
32-
| test-foundation-package | Build a package that imports Foundation |
33-
| test-import-glibc | Compile a source file importing and using Glibc |
34-
| test-multi-compile | Compile multiple source files into an executable |
35-
| test-multi-compile-glibc | Compile multiple source files importing Glibc into an executable |
36-
| test-static-lib | Compile multiple source files into a static library |
37-
| test-xctest-package | Build a package that imports XCTest |
24+
| Test Name | Functionality |
25+
|----------------------------|------------------------------------------------------------------|
26+
| basic | Check output of `swift --version` |
27+
| example-package-dealer | Build the example package-dealer package |
28+
| repl | Various REPL sanity checks, notably importing Darwin and Glibc |
29+
| swift-build-self-host | Use swift build to build itself |
30+
| swift-compiler | Compile a basic swift file |
31+
| test-c-library-swiftpm | Build a package that links a 3rd party library |
32+
| test-foundation-package | Build a package that imports Foundation |
33+
| test-import-glibc | Compile a source file importing and using Glibc |
34+
| test-multi-compile | Compile multiple source files into an executable |
35+
| test-multi-compile-glibc | Compile multiple source files importing Glibc into an executable |
36+
| test-static-lib | Compile multiple source files into a static library |
37+
| test-xctest-package | Build a package that imports XCTest |
38+
| test-swift-testing-package | Build a package that imports Swift Testing |
3839

3940

4041
## Contributing

swift-package-init-lib.md

+21-8
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
```
77
RUN: rm -rf %t.dir
88
RUN: mkdir -p %t.dir/Project
9-
RUN: %{swift-package} --package-path %t.dir/Project init --type library
9+
RUN: %{swift-package} --package-path %t.dir/Project init --type library --enable-xctest --enable-swift-testing
1010
RUN: %{swift-build} --package-path %t.dir/Project 2>&1 | tee %t.build-log
11-
RUN: %{swift-test} --package-path %t.dir/Project 2>&1 | tee %t.test-log
11+
RUN: %{swift-test} --package-path %t.dir/Project --enable-xctest --disable-swift-testing 2>&1 | tee %t.xctest-log
12+
RUN: %{swift-test} --package-path %t.dir/Project --disable-xctest --enable-swift-testing 2>&1 | tee %t.swift-testing-log
1213
```
1314

1415
## Check the build log.
@@ -21,23 +22,35 @@ RUN: %{FileCheck} --check-prefix CHECK-BUILD-LOG --input-file %t.build-log %s
2122
CHECK-BUILD-LOG: Compiling {{.*}}Project{{.*}}
2223
```
2324

24-
## Check the test log.
25+
## Check the XCTest log.
2526

2627
```
27-
RUN: %{FileCheck} --check-prefix CHECK-TEST-LOG --input-file %t.test-log %s
28+
RUN: %{FileCheck} --check-prefix CHECK-XCTEST-LOG --input-file %t.xctest-log %s
2829
```
2930

3031
```
31-
CHECK-TEST-LOG: Compiling {{.*}}ProjectTests{{.*}}
32-
CHECK-TEST-LOG: Test Suite 'All tests' passed
33-
CHECK-TEST-LOG-NEXT: Executed 1 test
32+
CHECK-XCTEST-LOG: Compiling {{.*}}ProjectTests{{.*}}
33+
CHECK-XCTEST-LOG: Test Suite 'All tests' passed
34+
CHECK-XCTEST-LOG-NEXT: Executed 1 test
35+
```
36+
37+
## Check the Swift Testing log.
38+
39+
```
40+
RUN: %{FileCheck} --check-prefix CHECK-SWIFT-TESTING-LOG --input-file %t.swift-testing-log %s
41+
```
42+
43+
```
44+
CHECK-SWIFT-TESTING-LOG: Test run started.
45+
CHECK-SWIFT-TESTING-LOG: Test run with 1 test passed after {{.*}} seconds.
3446
```
3547

3648
## Check there were no compile errors or warnings.
3749

3850
```
3951
RUN: %{FileCheck} --check-prefix CHECK-NO-WARNINGS-OR-ERRORS --input-file %t.build-log %s
40-
RUN: %{FileCheck} --check-prefix CHECK-NO-WARNINGS-OR-ERRORS --input-file %t.test-log %s
52+
RUN: %{FileCheck} --check-prefix CHECK-NO-WARNINGS-OR-ERRORS --input-file %t.xctest-log %s
53+
RUN: %{FileCheck} --check-prefix CHECK-NO-WARNINGS-OR-ERRORS --input-file %t.swift-testing-log %s
4154
```
4255

4356
```
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Testing
2+
3+
@Test func test_example() {
4+
print("HI")
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// swift-tools-version:6.0
2+
// Trivial test for importing Swift Testing.
3+
//
4+
// REQUIRES: platform=Linux
5+
//
6+
// Make a sandbox dir.
7+
// RUN: rm -rf %t.dir
8+
// RUN: mkdir -p %t.dir/tool
9+
// RUN: cp %s %t.dir/tool/Package.swift
10+
// RUN: cp %S/Tests.swift %t.dir/tool/Tests.swift
11+
// RUN: %{swift-build} --build-tests --package-path %t.dir/tool -v 2>&1 | tee %t.build-log
12+
//
13+
// Check the build log.
14+
//
15+
// RUN: %{FileCheck} --check-prefix CHECK-BUILD-LOG --input-file %t.build-log %s
16+
//
17+
// CHECK-BUILD-LOG: swiftc{{.*}} -module-name tool
18+
//
19+
// Verify that the tool exists and works.
20+
//
21+
// RUN: test -x %t.dir/tool/.build/debug/toolPackageTests.xctest
22+
// RUN: %t.dir/tool/.build/debug/toolPackageTests.xctest --testing-library swift-testing > %t.out
23+
// RUN: %{FileCheck} --check-prefix CHECK-TOOL-OUTPUT --input-file %t.out %s
24+
//
25+
// CHECK-TOOL-OUTPUT: HI
26+
27+
import PackageDescription
28+
29+
let package = Package(
30+
name: "tool",
31+
targets: [
32+
.testTarget(name: "tool", path: "./"),
33+
]
34+
)

0 commit comments

Comments
 (0)