Skip to content

Commit b974f32

Browse files
committed
[README] Add instructions on testing
1 parent 2ab7b8d commit b974f32

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ If your install of Swift is located at `/swift` and you wish to install XCTest i
3838
./build_script.py --swiftc="/swift/usr/bin/swiftc" --build-dir="/tmp/XCTest_build" --swift-build-dir="/swift/usr" --library-install-path="/swift/usr/lib/swift/linux" --module-install-path="/swift/usr/lib/swift/linux/x86_64"
3939
```
4040

41+
To run the tests, pass the `--test` option in combination with options to
42+
install XCTest in your active version of Swift, as well with the path to
43+
built LLVM binaries (which contain a program named `FileCheck`):
44+
45+
```sh
46+
./build_script.py \
47+
--swiftc="/swift/usr/bin/swiftc" \
48+
--build-dir="/tmp/XCTest_build" \
49+
--swift-build-dir="/swift/usr" \
50+
--library-install-path="/swift/usr/lib/swift/linux" \
51+
--module-install-path="/swift/usr/lib/swift/linux/x86_64" \
52+
--test \
53+
--native-llvm-tools-path="/llvm/build/Ninja-DebugAssert/llvm-macosx-x86_64/bin"
54+
```
55+
56+
To add additional tests to XCTest:
57+
58+
1. (Linux & OS X) Add a directory with the name of your test to the `Tests/Functional/Sources/` directory. For example, if your test is named "TwoFailingTestCases", make a directory named `Tests/Functional/Sources/TwoFailingTestCases`.
59+
1. (Linux & OS X) Add a `main.swift` file to the directory you added above. The file should contain comments, beginning with `// `. The test runner will verify that the output of `main.swift` matches your comments exactly. This is all you need to do to run tests on Linux--you may run the `build_script.py` example above to confirm the tests pass.
60+
1. (OS X) If you want your tests to run on OS X, open the `XCTest.xcodeproj` Xcode project and duplicate the `SingleFailingTestCase` target. Rename the target to match the name of your test. For example, if your test is named "TwoFailingTestCases", name the target `TwoFailingTestCases` as well.
61+
1. (OS X) In the "Compile Sources" build phase, set your `main.swift` file in place of the one in `SingleFailingTestCase`.
62+
1. (OS X) Add your new target to the "Target Dependencies" section of the `SwiftXCTestTests` aggregate build target's build phases. You may build the `SwiftXCTestTests` target to confirm the tests pass.
63+
4164
### Additional Considerations for Swift on Linux
4265

4366
When running on the Objective-C runtime, XCTest is able to find all of your tests by simply asking the runtime for the subclasses of `XCTestCase`. It then finds the methods that start with the string `test`. This functionality is not currently present when running on the Swift runtime. Therefore, you must currently provide an additional property called `allTests` in your `XCTestCase` subclass. This method lists all of the tests in the test class. The rest of your test case subclass still contains your test methods.

0 commit comments

Comments
 (0)