Skip to content
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

Integration on linux with "--enable-test-discovery" #11

Open
patrick-zippenfenig opened this issue Jul 23, 2020 · 3 comments
Open

Integration on linux with "--enable-test-discovery" #11

patrick-zippenfenig opened this issue Jul 23, 2020 · 3 comments

Comments

@patrick-zippenfenig
Copy link

Hi,

is there a way to use it with "--enable-test-discovery"?

As tests for linux are now automatically synthesised there is no LinuxMain.swift anymore.

Best, Patrick

@ar4s
Copy link
Contributor

ar4s commented Jul 27, 2020

When you build on linux environment you have to add test observer (SwiftTestReporter.TestObserver) and LinuxMain.swift is the best place for that.
Alternatively, you can generate LinuxMain.swift by following command swift test --generate-linuxmain --enable-test-discovery and then add observer.

@patrick-zippenfenig
Copy link
Author

Yes, this is basically using the old LinuxMain.swift approach. --generate-linuxmain will always generate a new LinuxMain.swift and remove the observer after every execution. With bash scripting the observer could be added afterwards, but this seems to be an ugly solution.

For a CI/CD integration that automatically adds news tests, I was hoping that there are other options to enable the observer without having to use LinuxMain.swift.

@aufflick
Copy link
Contributor

aufflick commented Feb 23, 2022

A hack I'm using is to create a test file AATests.swift with a no-op test that calls the initialization code, ie:

import XCTest
import SwiftTestReporter

class AATests: XCTestCase {
  func testAA() {
    _ = TestObserver()
  }
}

This works because only tests that start after the initialization will be captured, and (currently) spm evaluates tests in alphabetical order. If test order randomization happens one day this technique wouldn't work with that.

Another hack I thought of would be to make an Objective-C class that implements + load or + initialize and depend on that as a base class or otherwise cause the class to be loaded/initialized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants