Support multiple test plans
I received this request from fellow colleagues.
It is possible right now to execute the tool for every test plan individually, but it's not ideal since it would have to analyze the changeset several times.
One approach I was thinking about was to let pass an array of paths for the test plans so that the tool can process them all at once.
FWIW, I think an array makes sense.
It's somewhat tangential to the issue of multiple Test Plans, but another option to consider is using xcodebuild's built-in "-only-testing" param to side-step editing Test Plans entirely. e.g.:
% xcodebuild test -scheme SampleApp "-only-testing:SomeTarget1" "-only-testing:SomeTarget2" "-only-testing:SomeTarget3"
Especially for CI purposes. If the executable could generate a json file with a simple array of these target strings (i.e., {"affectedTargets" : ["SomeTarget1", "SomeTarget2", ...]}), and save the file to some absolute or relative path passed in from a cli argument, it would be easy for CI systems to parse the json, and add the "-only-testing:SomeTarget1" etc. to a downstream xcodebuild command.
That way you could apply the same list of -only-testing targets to any Test Plan and it would apply the same target filter. It would also work for use cases which don't use Test Plans.
Hey @Pierce-Evan ,
thanks for the suggestion, to be honest, I was not aware of -only-testing flag, I think it is indeed quite a valuable addition.
With a small help of jq and a ton of backslashes, it is in fact possible to achieve it with the current setup, at least for me it worked:
swift run xcode-selective-test . --json | jq -r ". | map(\"\\\"-only-testing:\" + .name + \"\\\"\") | join(\" \")"
Building for debugging...
Build complete! (0.14s)
Finding changeset for repository at .
"-only-testing:SelectiveTestingCore" "-only-testing:SelectiveTestingTests" "-only-testing:xcode-selective-test" "-only-testing:DependencyCalculatorTests" "-only-testing:Git" "-only-testing:SelectiveTestingPlugin" "-only-testing:DependencyCalculator"
Let me play with it a bit more to make sure it would actually work and I would add it to the README file.
So, with #8 it is possible to achieve it. This PR is necessary to support excluding non-testing targets. xcodebuild is complaining when it is asked to test non-test targets.
xcodebuild test -workspace Workspace.xcworkspace -scheme Scheme $(mint run --silent XcodeSelectiveTesting@provide-if-target-is-test-target --json | jq -r "[.[] | select(.testTarget == true)] | map(\"-only-testing:\" + .name) | join(\" \")")
In a way, the command looks like a mishmash, but to me, it is also a manifestation of Unix philosophy.
Please give it a try and share your thoughts.