"Watch mode" for tests

Hi everyone,

A colleague of mine created a rudimentary solution to run swift test in a 'watch mode'. I.e. tests get rerun every time you save a file.

He is considering contributing this to Swift.

My questions would be:

  • Is this functionality you would like?
  • Is this something that is already worked on (an issue or PR link would be nice)
  • Where would this live? In the Swift toolchain and/or in Swift-Testing?

KR Maarten

2 Likes

This sounds like useful functionality for a CI system or an IDE, but probably not for Swift Testing itself. Swift Testing isn't really concerned with how it gets run, and prefers to leave that up to whatever tool is triggering testing (be it Xcode, VS Code, Jenkins, swift test, etc.)

Without speaking for the Swift Package Manager code owners, I could see this potentially being a useful tool in the swift test command. Any implementation needs to be portable/cross-platform however, and must work on the major host platforms supported by Swift Package Manager (currently macOS, Linux, and Windows, but potentially other platforms in the future.) Does your colleague's implementation work across all those platforms?

A next step could be forking the SPM repo and adding the code there; then we could all check out the forked package, build it at desk, try it out, etc.

1 Like

I think it generalizes even further than that; an "interactive swift build" would be useful as well, where changes to the watched source files would just kick off a new build command automatically. The added benefit for swift test is that it could also rerun the tests afterwards, of course, if the user wanted that.

2 Likes

The current solution is just a Swift script that watches the filesystem and runs swift test when it finds changes. So it is far from anything that could be upstreamed. It does run on Linux and macOS though.

But it does seem that there is some interest for something like this. And that it would probably be part of Swift PM. I'll take this up with my colleague.