-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Allow tests to link against executable targets #3103
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
Allow tests to link against executable targets #3103
Conversation
@swift-ci please smoke test |
I think that we should possibly look at an older change of mine - marking BTW, strip is technically not available on Windows (although the current Swift toolchains being distributed do include it and thus would be there). |
Yes, doing this on the .o production side would definitely be better, though it wouldn't allow testing of Clang executables (not sure how important that is but it would be somewhat inconsistent). I'm not sure how feasible such a change would be, or how long that would take, but editing the symbol after-the-fact is definitely a stopgap.
Right, that's what I actually meant to say (that it's currently available in the toolchain). I think on Linux as well, it comes from |
9507ec2
to
f25f609
Compare
|
||
var tests = [XCTestCaseEntry]() | ||
tests += TestableExeTests.allTests() | ||
XCTMain(tests) |
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.
should not be required any longer?
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.
Probably not. I’ll try without it.
testCase(TestableExeTests.allTests), | ||
] | ||
} | ||
#endif |
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.
should not be required any longer?
@swift-ci please smoke test |
a6fd23c
to
1f58ae7
Compare
@swift-ci please smoke test |
…ort and test the code. Since compiler support isn't yet available, this implementation elides the `_main` symbol from the linked binary (using `nmedit` on Darwin and `objcopy` elsewhere). To produce alternate versions of .o files for the unit test to link against.
1f58ae7
to
c8da0e3
Compare
Update: I will be reworking this to use the new Swift compiler flag in swiftlang/swift#35595. |
This is superseded by #3316 so I'm withdrawing this PR. |
So removing all testing references. Reference for main statement: swiftlang/swift-package-manager#3103
Experimental changes to allow test products to link against both Swift and Clang executable targets. This allows them to test everything except the main function in those targets without having to run the executable as a subprocess.
Motivation:
Many package authors don’t want to split their code into executable targets vs library targets, but still want to test data structures and algorithms in their executables.
Modifications:
This is experimental and not suitable for merging yet. It uses
nmedit
to elide the_main
symbols from .o files from executables when a test product links them. This only works on Darwin; on Linux and Windows, thestrip
tool should usable but that hasn’t yet been tried.There are several issues to address:
In the long run it would be better to have Swift and Clang changes to conditionally emit any
_main
symbol to a separate .o file that could be either included or excluded from a particular link command.Result:
Unit tests that declare dependencies on executable targets will link against that code as well. We will need to consider the compatibility impacts of this, and might need to tie it to a tools version.
rdar://58122395