Skip to content

0.7.0

Choose a tag to compare

@github-actions github-actions released this 26 Nov 00:51
37c8a2b

Added

  • TestClock, a clock that moves only when the test moves it, so code that waits can be tested without real time passing. advance(by:) and advance(to:) wake each sleep the window reaches, in deadline order, and let the woken code run on to its next sleep, even across actors and the main actor; a woken task reads now as the deadline it woke at, so a sleep it starts late still counts from then; advance() lets ready work run, and run() moves on until nothing waits. A cancelled sleep throws CancellationError. It needs macOS 13, iOS 16, tvOS 16 or watchOS 9.
  • @GenerateSpies on a protocol with associated types writes a generic spy, one generic parameter per associated type with its constraints (Sendable added in a Sendable protocol and in an actor protocol): RepositorySpy<Product>(). A where clause on an associated type or on the protocol, and a static requirement next to an associated type, are refused with a message pointing to the class form.
  • @GenerateSpies on a protocol that inherits another protocol with @GenerateSpies writes a spy that stores the parent's spy, taken first by its initializer, ChildSpy(base: BaseSpy(ping: 3)), and answers the parent's requirements through it, with the parent's spies read on the child's (child.pingSpy). Several parents and a parent's parents work too. For this, the macro also writes <Name>SpyForwarding next to every protocol. A parent from the standard library, a parent with associated types, an actor protocol, and a protocol declared inside another type can't be forwarded to, and say so.
  • .verifiesMocks, a Swift Testing trait for a test or a suite (Swift 6.1 or later): every spy given an expectation during the test is verified when it ends, so a forgotten verify() can't pass silently. An unmet expectation is reported at its expect line, and a call nobody expected at the test; a spy with no expectations is never checked, and a problem verify() already reported isn't reported again. expect gains a defaulted sourceLocation, so existing calls compile unchanged.
  • .spi.yml, so the Swift Package Index builds the package and hosts the API docs of Understudy and UnderstudySamples.
  • A coverage report on Codecov for main and each pull request (the Coverage report workflow). scripts/check-coverage.sh writes the measured lines as one LCOV file when COVERAGE_LCOV names a path. The coverage gate itself is unchanged.

Changed

  • Breaking, only for a test that declares its own type named <Name>SpyForwarding next to a protocol with @GenerateSpies: the macro now writes a protocol of that name there, so the two clash. Rename the test's type.
  • Breaking, only for code that keeps a strict spy's expect as a function value: expect(_:times:) and expect(times:where:) gained a sourceLocation that defaults to the caller's, so .verifiesMocks can point at the expect line. Calls don't change. expect and expectNoCalls() now live, like verify, only where Swift Testing can be imported, which every supported toolchain can; without it a strict spy could never report.
  • Pull requests run the tests on Swift 6.0 and 6.4 only. Swift 6.1, 6.2 and 6.3 run on every push to main, in the Linux checks a release waits for, so every version still passes before a version is published.
  • CodeRabbit's review checks the shared code style and clean code (short functions, clear names, no repeated logic), and says exactly which macro test checks are wanted. SonarQube Cloud keeps tests apart from sources and leaves coverage to Codecov, Codecov reports through statuses only, and CODE_STYLE.md no longer contradicts itself on macro tests. The review uses the chill profile and reports broken style and testing rules inline as should-fix findings, so an open one blocks the merge.
  • Every test has a display name that states what it checks, such as "A spy keeps every input in order", so a test report reads as a list of what the package promises. Test function names stay as they were, for swift test --filter.

Fixed

  • The code @GenerateSpies writes names every type it uses with its module (Understudy.Spy, Understudy.PropertySpy, Swift.Void, _Concurrency.TaskLocal and the rest), so a double still builds next to a type of the test's own called Spy, Void or TaskLocal. @Sample's defaults keep the type as the property writes it, so they follow a type of the app's own called Date or URL.