Skip to content

Ensure temp dir is different between testIncremental and testIncrementalDiagnostics to see if that fixes the test breakage in CI #374

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

Merged
merged 5 commits into from
Nov 18, 2020

Conversation

davidungar
Copy link
Contributor

Best theory to explain a mysterious test failure on CI Linux. Land it and if test starts failing, disable the test again.

David Ungar added 2 commits November 17, 2020 14:26
…talDiagnostics to see if that fixes the test breakage in CI
@davidungar
Copy link
Contributor Author

@swift-ci please test

@davidungar davidungar requested a review from artemcm November 17, 2020 22:31
Copy link
Contributor

@artemcm artemcm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a better way to do this that avoids having to use #line and remembering to call prepare on new tests:

We can keep the setUp method in place and use the self.name XCTestCase property for the prefix on withTemporaryDirectory. This name property will have the format that, for a given test, looks like this:
"-[IncrementalCompilationTests testIncrementalDiagnostics]"

self.name docs:
https://developer.apple.com/documentation/xctest/xctest/1500990-name

@@ -357,12 +358,12 @@ final class IncrementalCompilationTests: XCTestCase {

// FIXME: why does it fail on Linux in CI?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for reviewing so quickly. Nice catch!

@cltnschlosser
Copy link
Contributor

What about removing the setup all together and wrapping the tests in withTemporaryDirectory. Has the additional benefit of deleting the folder after the test completes.

@davidungar
Copy link
Contributor Author

@swift-ci please test

@davidungar
Copy link
Contributor Author

I think there is a better way to do this that avoids having to use #line and remembering to call prepare on new tests:

We can keep the setUp method in place and use the self.name XCTestCase property for the prefix on withTemporaryDirectory. This name property will have the format that, for a given test, looks like this:
"-[IncrementalCompilationTests testIncrementalDiagnostics]"

self.name docs:
https://developer.apple.com/documentation/xctest/xctest/1500990-name

I like your idea! I found a refinement, of overriding the constructor, so that tempDir can be constant. Thanks.

@davidungar
Copy link
Contributor Author

What about removing the setup all together and wrapping the tests in withTemporaryDirectory. Has the additional benefit of deleting the folder after the test completes.

Thanks for looking at this. Even if setup is removed, all that stuff has to go somewhere. Somehow it seems easier to factor this way. And there is a deinit to rm the temp dir.

@cltnschlosser
Copy link
Contributor

Okay, yeah these tests you would have to pass the temp directory through quite a few layers, so this approach is definitely easier. Normally I think the closure approach is superior. We use it in other places.

  func testInputModifiedDuringSingleJobBuild() throws {
    try withTemporaryDirectory { path in
      let main = path.appending(component: "main.swift")
      try localFileSystem.writeFileContents(main) {
        $0 <<< "let foo = 1"
      }

      var driver = try Driver(args: ["swift", main.pathString])
      let jobs = try driver.planBuild()
      XCTAssertTrue(jobs.count == 1 && jobs[0].requiresInPlaceExecution)

      // Change the file
      try localFileSystem.writeFileContents(main) {
        $0 <<< "let foo = 1"
      }

      XCTAssertThrowsError(try driver.run(jobs: jobs)) {
        XCTAssertEqual($0 as? Job.InputError,
                       .inputUnexpectedlyModified(TypedVirtualPath(file: .absolute(main), type: .swift)))
      }

    }
  }

@davidungar
Copy link
Contributor Author

@swift-ci please test

@davidungar davidungar merged commit db1e474 into swiftlang:main Nov 18, 2020
@davidungar
Copy link
Contributor Author

Thanks, @artemcm

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

Successfully merging this pull request may close these issues.

3 participants