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
[Tests] Add functional tests #20
Conversation
f352a83
to
466522e
Compare
// CHECK: .*/Tests/Functional/SingleFailingTestCase/main.swift:24: error: SingleFailingTestCase.test_fails : | ||
// CHECK: Test Case 'SingleFailingTestCase.test_fails' failed \(\d+\.\d+ seconds\). | ||
// CHECK: Executed 1 test, with 1 failure 0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds | ||
// CHECK: Total executed 1 test, with 1 failure \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FileCheck
uses a special syntax for regular expressions. xctest_checker
parses everything as a regular expression. As a result, developers need to take extra care to escape certain characters when writing their checks--for example, 1 failure \(0 unexpected\)
.
This is suboptimal, and could be improved in the future, but xctest_checker
remains a simple program as a result of this decision.
Thanks, Brian! As I mentioned last week, I am out of the office traveling until after New Years but I will take a closer look as soon as I get back. Mike
|
Yeah, thanks for the heads-up on the mailing list. Enjoy the holidays! 🎄 |
466522e
to
2aad49a
Compare
2aad49a
to
74a4ae7
Compare
I rebased on top of #23. The tests still pass! I also added a blurb to the
This is because the tests require the |
856edba
to
7688c68
Compare
// RUN: %built_tests_dir/SingleFailingTestCase > %test_output || true | ||
// RUN: %xctest_checker %test_output %s | ||
// CHECK: Test Case 'SingleFailingTestCase.test_fails' started. | ||
// CHECK: .*/Tests/Functional/SingleFailingTestCase/main.swift:24: error: SingleFailingTestCase.test_fails : XCTAssertTrue failed - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rebased on top of #22; the tests verify the new output from @briancroom's updates.
7688c68
to
bc7c756
Compare
I asked a couple questions in the diff about the workings of xctest_checker. I also noticed the following.
|
I would also suggest adding the Tests folder to the Xcode project (as groups, with no target membership) just to make it easier to work on the tests for us OS X folks. |
bc7c756
to
70533fa
Compare
Overall, this looks like a good lit integration for XCTest. I added a couple of specific comments on the lit.cfg to the initial commit. There a couple of follow ons we could do to make things even more convenient:
|
One more thing to mention is that I also have a "reverse-adaptor" which adapts XCTest to lit. Since lit has the ability to run multiple test suites as part of a single invocation, then if we get to the point where the XCTest project has a lot of XCTest based tests in it, we can also provide an integration so that the lit-based invocation will run all of the tests (both the lit and the XCTest ones). |
Oomph, turns out that when you comment on an individual commit, and that commit is amended (such that its hash changes), the comments no longer appear alongside the pull request. Here's the commit that includes review comments: modocache@eed9cdb If you're using the GitHub web interface, try commenting on the "Files changed" tab instead: |
70533fa
to
b5e0160
Compare
@mike-ferris-apple I've addressed all of your comments--thanks!
Thanks for pointing this out. I've amended the XCTest checker such that the number of actual and expected lines must match. I've also added Python tests for this behavior.
Awesome, thanks to this suggestion developers no longer need to use I'm still working on @ddunbar's comments. |
Cool. And presumably if they do have a custom toolchain active, that should work as well with this build setting, I think. Mike
|
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. - Because FileCheck is not available unless LLVM is built, includes an XCTest-specific version of FileCheck called `xctest_checker`. This is used by the lit tests in order to verify the output of XCTest runs. - Adds a test case that verifies the output of a single failing test case. - To run the tests on Linux, adds a `--test` option to `build_script.py`. - To run the tests on OS X, adds a `SwiftXCTestFunctionalTests` target to the Xcode project.
b5e0160
to
a84cf7f
Compare
@ddunbar I've addressed all of your comments, except for one:
That was indeed my intention! As per your suggestions I tried the following: diff --git a/Tests/Functional/SingleFailingTestCase/main.swift b/Tests/Functional/SingleFailingTestCase/main.swift
index 2cffe97..a4f4802 100644
--- a/Tests/Functional/SingleFailingTestCase/main.swift
+++ b/Tests/Functional/SingleFailingTestCase/main.swift
@@ -1,6 +1,6 @@
// RUN: %{swiftc} %s -o %{built_tests_dir}/SingleFailingTestCase
-// RUN: %{built_tests_dir}/SingleFailingTestCase > %{test_output} || true
-// RUN: %{xctest_checker} %{test_output} %s
+// RUN: %{built_tests_dir}/SingleFailingTestCase > %t || true
+// RUN: %{xctest_checker} %t %s
// CHECK: Test Case 'SingleFailingTestCase.test_fails' started.
// CHECK: .*/Tests/Functional/SingleFailingTestCase/main.swift:24: error: SingleFailingTestCase.test_fails : XCTAssertTrue failed -
// CHECK: Test Case 'SingleFailingTestCase.test_fails' failed \(\d+\.\d+ seconds\).
diff --git a/Tests/Functional/lit.cfg b/Tests/Functional/lit.cfg
index 6f9aafc..71d22cd 100644
--- a/Tests/Functional/lit.cfg
+++ b/Tests/Functional/lit.cfg
@@ -8,6 +8,7 @@ import lit
config.name = 'SwiftXCTestFunctionalTests'
config.test_format = lit.formats.ShTest(execute_external=False)
config.suffixes = ['.swift']
+config.text_exec_root = tempfile.mkdtemp()
# Set up the substitutions used by the functional test suite. But running the tests still results in |
This looks good to me. We can iterate with another pull request if the %t thing @ddunbar mentions gets resolved. |
[Tests] Add functional tests
Awesome, thanks @mike-ferris-apple! Very happy to see this in. 👍 |
Excellent! This will greatly assist in further work on this project. |
What's in this pull request?
Yet another attempt at #10, this pull request adds functional tests that verify the output of programs that use XCTest. This pull request is based off of the discussion on #14, and uses
lit
as a test runner.A developer can kick off the tests by either running
build_script.py --test
or by building and running theSwiftXCTestFunctionalTests
Xcode target.Here's a breakdown of what happens when a user kicks off the tests:
../llvm/utils/lit/lit.py Tests/Functional
is run, which kicks off the configuration inTests/Functional/lit.cfg
.lit.cfg
uses environment variables to provide substitutions, such as%swiftc
, to the tests. On Linux, these environment variables are set as part ofbuild_script.py
. On OS X, these environment variables are provided byxcodebuild
.lit
finds every Swift source file that contains aRUN:
command and executes those commands.RUN:
commands inSingleFailingTestCase/main.swift
compiles the source into an executable in a temporary directory, runs that executable, and checks the output. Output verification is done viaxctest_checker
, a Python script.Why merge this pull request?
Tests/Functional/MyNewTest/main.swift
. Unlike [Tests] Add regression test suite for OS X and Linux #10 and Add lit tests #14, new tests don't need to be configured in the Xcode project to work.What downsides are there to merging this pull request?
lit
, is dependent upon thellvm
codebase being installed in../llvm
. Alternatively, it could check forpip
oreasy_install
being installed on the host system, and if available use them to install https://pypi.python.org/pypi/lit. Either way, the test suite is not completely independent: it relies on eitherllvm
being cloned ahead of time, or on an Internet connection to installlit
from the Python Package Index.lit
is unable to do so. The tests verify the output, but not whether the exit code emitted by XCTest indicated a failure. @ddunbar, is it possible to test this usinglit
?