0

I added the Debounce class taken from here: https://stackoverflow.com/a/59296478/945247

This class has the unit test below which passes locally but fails on AppCenter with the error "Variable used within its own initial value":

func test_entering_text_delays_processing_until_settled() {
    let expect = expectation(description: "processing completed")
    
    var finalString: String = ""
    var timesCalled: Int = 0
    
    let process: (String) -> () = {
        finalString = $0
        timesCalled += 1
        expect.fulfill()
    }

    Debounce<String>.input("A", comparedAgainst: "AB", perform: process)
    Debounce<String>.input("AB", comparedAgainst: "ABCD", perform: process)
    Debounce<String>.input("ABCD", comparedAgainst: "ABC", perform: process)
    Debounce<String>.input("ABC", comparedAgainst: "ABC", perform: process)

    wait(for: [expect], timeout: 2.0)

    XCTAssertEqual(finalString, "ABC")
    XCTAssertEqual(timesCalled, 1)
}

I can't see anyting in that code which would cause that error, let alone just on AppCenter.

Edit:

Here's the full details I have from the AppCenter logs:

2021-10-06T16:05:31.0647180Z Testing failed:
2021-10-06T16:05:31.0647560Z    Variable used within its own initial value
2021-10-06T16:05:31.0647980Z    Testing cancelled because the build failed.
2021-10-06T16:05:31.0648180Z 
2021-10-06T16:05:31.0648460Z ** TEST FAILED **
2021-10-06T16:05:31.0648610Z 
2021-10-06T16:05:31.0648720Z 
2021-10-06T16:05:31.0649050Z The following build commands failed:
2021-10-06T16:05:31.0649560Z    CompileSwift normal x86_64 /Users/runner/work/1/s/AppTests/Utilities/DebounceTests.swift
2021-10-06T16:05:31.0650120Z    CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler

I have been able to confirm that it's the debounce tests which are causing the failure because I commented out the above test and the app built, when I uncommented it the build failed with the same error.

Leon
  • 3,614
  • 1
  • 33
  • 46
  • Sorry for being ignorant, but what is "AppCenter"? Also, can you say any more about what line triggers the error? This is evidently a compile error so there ought to be line number information. – matt Oct 06 '21 at 16:18
  • Hi matt, AppCenter: https://appcenter.ms which includes tools for CI/CD. There's no line number unfortunately, just an entry in the AppCenter build logs. – Leon Oct 06 '21 at 16:32
  • No line number for the compile error? Strange, as xcodebuild surely gives such information. – Cristik Oct 06 '21 at 17:18
  • Also, if you don't know the line number, how do you know that the problem is in that piece of code you posted in the question? – Cristik Oct 06 '21 at 17:20
  • @Cristik Please see my edit. – Leon Oct 08 '21 at 16:38

0 Answers0