Avoid traversing array in TestDiscoveryCommand twice (#2784)
Avoid traversing array in TestDiscoveryCommand twice (#2784)

* Avoid traversing the outputs array in TestDiscoveryCommand twice

Currently the `outputs` array in `TestDiscoveryCommand.execute` function is traversed twice. Once in a `for` loop that writes tests for each module, and second time in the `first(where:)` call just after the loop. The loop also checks for the main file anyway to skip it, so there's an opportunity for an easy optimization here, which could be felt in packages with big test suites.

* Check whether mainFile is nil in the outputs loop
abertelrud/swift-package-manager,apple/swift-package-manager,abertelrud/swift-package-manager,apple/swift-package-manager,abertelrud/swift-package-manager,abertelrud/swift-package-manager,apple/swift-package-manager,abertelrud/swift-package-manager,apple/swift-package-manager,apple/swift-package-manager