skiptools / skiptools/skip

Skip transpiler fails transpiling XCTest with async setup

Open
#651 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
3.2k
Forks
106
Avg merge
6d 13h
Merged PRs (30d)
1

Description

import XCTest

final class AsyncSetUpTranspilerReproTests: XCTestCase {
    private var valueFromAsyncSetUp: String!

    override func setUp() async throws {
        try await super.setUp()
        valueFromAsyncSetUp = try await Self.sleepThenReturnExpectedString()
    }

    private static func sleepThenReturnExpectedString() async throws -> String {
        try await Task.sleep(nanoseconds: 10_000_000)
        return "expected-after-sleep"
    }

    func testAsyncSetUpStoresExpectedString() throws {
        XCTAssertEqual(valueFromAsyncSetUp, "expected-after-sleep")
    }
}

This test passes in native Swift, but, after transpilation, it fails to compile.

e: file:///private/tmp/tp/lib-project/.build/plugins/outputs/lib-project/ModuleNameTests/destination/skipstone/ModuleName/src/test/kotlin/module/name/AsyncSetUpTranspilerReproTests.kt:11:26 Suspend function 'setUp' cannot override non-suspend function 'fun setUp(): Unit' defined in 'skip.unit.XCTestCase'.

The setUp() function transpiles to this:

override suspend fun setUp(): Unit = Async.run {
    super.setUp()
    valueFromAsyncSetUp = Companion.sleepThenReturnExpectedString()
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Swift XCTest reproduction and the generated Kotlin file at .build/plugins/outputs/lib-project/ModuleNameTests/destination/skipstone/ModuleName/src/test/kotlin/module/name/AsyncSetUpTranspilerReproTests.kt. Trace how async XCTest setUp is transpiled and compare the generated override with skip.unit.XCTestCase. Done means the transpiled test compiles and passes like the native Swift test.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, swift
Domain
mobile-dev, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.