-
Notifications
You must be signed in to change notification settings - Fork 263
Add lit tests #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lit tests #14
Conversation
Adds a test runner (lit) that compares annotations in the source code of an XCTest file to actual output when that source code is compiled and run. This acts as a regression test suite for the project. Adds two new Xcode targets: 1. SingleFailingTestCase: An executable that runs `XCTMain()` with a failing test case. It is built and installed to the Tests/Fixtures/Products/ directory. 2. SwiftXCTestTests: An aggregate target that builds SingleFailingTestCase (and, in the future, all test fixtures), then runs the lit test runner, passing the path the `FileCheck`, another LLVM tool that is used to test the output.
By passing `--test` to the build script, the lit regression tests are run. This allows the test suite to be run on Linux. Require the path to `FileCheck` be passed along as well.
27e2bfb
to
b974f32
Compare
In hindsight, it might be nicer to ask developers to simply add FileCheck to their PATH, rather than have the Linux and OS X build systems require additional arguments. Thoughts? 🙌 |
I do think that the amount of work required on the OS X side for adding new tests is unfortunate. The more I think about this, the more I think that I would really prefer that the tests actually be written as XCTests. I have been working on broadening the framework implementation to allow this and I am hoping to have a patch ready in the near future that will get us to that point. If we had support for XCTestObservation in the framework, I think it would go a long way to providing the testability we need. There might still be use for the kind of black box testing we could get from a tool like lit, though. For example, the test in your pull request could be written as an XCTest and verify that the test ran, had the expected failures, etc… but would not be able to verify the exact console output. I would suggest that: I’d also be interested in whether Daniel has any suggestions on simplifying the requirements here. Your additions to the ReadMe don’t mention it, but does running these tests require getting and installing lit on the system separately? Mike
|
Ack, you're right! I had thought it was placed on a user's
I think the majority of the work here is to add executable targets and add them as dependencies to the aggregate target. If I knew how to compile I can't tell if I'm missing something, or if it's actually pretty tough to do this. It might be simpler if we adapted
Awesome!! Can't wait! 😍 Let me know if there's anything I can help with. I think we discussed methods like |
So most of my work so far has been around fixing that by implementing enough of the surrounding model of XCTest to support that. Mike
|
Ok, first off a couple comments on the implementation:
The best way to do this is to write a helper tool which performs the boilerplate (building the test appropriately for each platform).
Obviously before we pursue these things more we should decide on what our exact approach is going to be. As far as the dependencies question, if we did go this direction I would suggest:
|
Oops, sorry for the slow turnaround! 🐌
@mike-ferris-apple This seems reasonable to me.
@mike-ferris-apple Yeah, I looked into this a while back; this has been the model since OCUnit. Have you spoken to the Objective-C XCTest team? I bet they have a ton of context on the problem space.
@ddunbar I was thinking, and based on @mike-ferris-apple's comments above, that this helper tool should have two incarnations: a script used for Linux, and an Xcode project target for OS X. Does that sound reasonable?
@ddunbar This pull request adds a script execution phase to the Xcode project that runs
This makes sense to me. Should this be a Python module in the swift-corelibs-xctest repository? Based on the above, I think the direction I'll take here is as follows: swift-corelibs-xctest/
XCTest.xcodeproj/ # Updated with a FunctionalTests target, which builds the Functional/Sources/ and runs lit
XCTest/
Tests/ # Tests directory for this project.
Functional/ # Functional tests that use lit. They're in their own sub-directory to differentiate from the unit tests we'll be adding in the future
Sources/ # A collection of main.swift files that run XCTMain()
Products/ # The built products from Tests/Fixtures/Sources/ go here. They'll be .gitignore'd
lit.cfg # The lit config for these tests. Adds xctest-checker to the Python path
xctest-checker/ # A Python module for verifying the output of XCTest runs
build_script.py # Updated with a --test parameter, to build and run the tests on Linux Adding a test will involve two steps:
Does all that sound reasonable? 🙌 |
|
Good point, will do! 👍
Another great point! Based on the above, here's the structure I'm envisioning: swift-corelibs-xctest/
XCTest.xcodeproj/ # Updated with a FunctionalTests target, which builds the Functional/Sources/ and runs lit
XCTest/
Tests/ # Tests directory for this project.
Functional/ # Functional tests that use lit. They're in their own sub-directory to differentiate from the unit tests we'll be adding in the future
xctest-checker/ # A Python module for verifying the output of XCTest runs
lit.cfg # The lit config for these tests. Adds xctest-checker to the Python path
build_script.py # Updated with a --test parameter, to build and run the tests on Linux When adding a test named "TwoFailingTestCases", developers will add a file named |
Closing in favor of #20. Thanks for your feedback, everyone!! 😃 |
Another attempt at #10! See the discussion on that pull request, plus the commit messages on this one, for details on the approach I'm taking. 🌂
As @ddunbar suggested in the comments for the last pull request, I tried using
lit
instead of a custom test runner script. Unfortunately, I think I might be doing something wrong, since I ended up adding two dependencies in the process:lit
itself, which could be installed via https://pypi.python.org/pypi/litFileCheck
, which is included in the LLVM built products directorybin
It seems like nearly all of the
lit
tests in the LLVM and Swift projects useFileCheck
. Unfortunately, it's not distributed outside of LLVM. As a result, these tests require that users have built Swift prior to running the test suite.I also couldn't find a nice way to pass the LLVM
bin
path to the Xcode project. It now assumes that LLVM is built in a specific location relative to this project's source directory:Ideally, we could just reuse the
lit.cfg
from the Swift project, which would not only get us the LLVMbin
path, but also neat substitutions like%target-swiftc_driver
. Those would allow us to replace the OS X-specific steps from the "adding tests" section of the README (also added in this pull request). But it turns out the Swiftlit.cfg
is very tightly coupled to the Swift build script and the environment variables it exports--it'd be a lot more work to separate those two.I'm not really sure how to proceed, so feedback would be appreciated. I'd love to add some regression tests to this project.