Skip to content

Commit

Permalink
Move (slow) regression tests to end
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Mar 28, 2024
1 parent 1b0730b commit ca70962
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 55 deletions.
4 changes: 4 additions & 0 deletions SwiftFormat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
01C209B92502D3C500E728A2 /* RulesTests+Wrapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C209B82502D3C500E728A2 /* RulesTests+Wrapping.swift */; };
01C209BB2502D62000E728A2 /* RulesTests+Organization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C209BA2502D62000E728A2 /* RulesTests+Organization.swift */; };
01C209BD2502D71F00E728A2 /* RulesTests+Redundancy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C209BC2502D71F00E728A2 /* RulesTests+Redundancy.swift */; };
01C4D3292BB518D400BDF1AF /* ZRegressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C4D3282BB518D400BDF1AF /* ZRegressionTests.swift */; };
01D3B28624E9C9C700888DE0 /* FormattingHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01D3B28524E9C9C700888DE0 /* FormattingHelpers.swift */; };
01EF830F25616089003F6F2D /* RulesTests+Syntax.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EF830E25616089003F6F2D /* RulesTests+Syntax.swift */; };
01EFC8B729CF2B5100222029 /* RulesTests+Hoisting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EFC8B629CF2B5100222029 /* RulesTests+Hoisting.swift */; };
Expand Down Expand Up @@ -225,6 +226,7 @@
01C209B82502D3C500E728A2 /* RulesTests+Wrapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RulesTests+Wrapping.swift"; sourceTree = "<group>"; };
01C209BA2502D62000E728A2 /* RulesTests+Organization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RulesTests+Organization.swift"; sourceTree = "<group>"; };
01C209BC2502D71F00E728A2 /* RulesTests+Redundancy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RulesTests+Redundancy.swift"; sourceTree = "<group>"; };
01C4D3282BB518D400BDF1AF /* ZRegressionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZRegressionTests.swift; sourceTree = "<group>"; };
01D3B28524E9C9C700888DE0 /* FormattingHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormattingHelpers.swift; sourceTree = "<group>"; };
01EF830E25616089003F6F2D /* RulesTests+Syntax.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RulesTests+Syntax.swift"; sourceTree = "<group>"; };
01EFC8B629CF2B5100222029 /* RulesTests+Hoisting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RulesTests+Hoisting.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -411,6 +413,7 @@
01BBD85D21DAA30700457380 /* GlobsTests.swift */,
018E82741D62E730008CA0F8 /* TokenizerTests.swift */,
011A53E921FFAA3A00DD9268 /* VersionTests.swift */,
01C4D3282BB518D400BDF1AF /* ZRegressionTests.swift */,
);
path = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -826,6 +829,7 @@
01EF830F25616089003F6F2D /* RulesTests+Syntax.swift in Sources */,
01BBD85E21DAA30700457380 /* GlobsTests.swift in Sources */,
01B3987B1D763424009ADE61 /* FormatterTests.swift in Sources */,
01C4D3292BB518D400BDF1AF /* ZRegressionTests.swift in Sources */,
01C209BD2502D71F00E728A2 /* RulesTests+Redundancy.swift in Sources */,
0142F06F1D72FE10007D66CC /* SwiftFormatTests.swift in Sources */,
01C209AF2502CD3C00E728A2 /* RulesTests+Spacing.swift in Sources */,
Expand Down
28 changes: 0 additions & 28 deletions Tests/CommandLineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,6 @@ class CommandLineTests: XCTestCase {
XCTAssertNotEqual(computeHash(input), computeHash(output))
}

// MARK: end-to-end formatting

func testFormatting() {
CLI.print = { _, _ in }
let args = ". --dryrun --disable redundantSelf"
XCTAssertEqual(CLI.run(in: projectDirectory.path, with: args), .ok)
}

// MARK: rules

func testRulesNotMarkedAsDisabled() {
Expand Down Expand Up @@ -566,24 +558,4 @@ class CommandLineTests: XCTestCase {
], in: "")
}
}

// MARK: snapshot/regression tests

func testRegressionSuite() {
CLI.print = { message, _ in
Swift.print(message)
}
// NOTE: to update regression suite, run again without `--lint` argument
XCTAssertEqual(CLI.run(in: projectDirectory.path, with: "Sources,Tests,Snapshots --unexclude Snapshots --symlinks follow --cache ignore --lint"), .ok)
}

func testRegressionSuiteNotDisabled() throws {
let commandLineTests = try String(contentsOf: URL(fileURLWithPath: #file))
let range = try XCTUnwrap(
commandLineTests.range(of: "testRegressionSuiteNotDisabled()")
)
XCTAssert(commandLineTests[..<range.lowerBound].contains("""
with: "Sources,Tests,Snapshots --unexclude Snapshots --symlinks follow --cache ignore --lint")
"""))
}
}
4 changes: 2 additions & 2 deletions Tests/GlobsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ class GlobsTests: XCTestCase {
func testExpandPathWithWildcardAtStart() {
let path = "*Tests.swift"
let directory = URL(fileURLWithPath: #file).deletingLastPathComponent()
XCTAssertEqual(try matchGlobs(expandGlobs(path, in: directory.path), in: directory.path).count, 15)
XCTAssertEqual(try matchGlobs(expandGlobs(path, in: directory.path), in: directory.path).count, 16)
}

func testExpandPathWithSubdirectoryAndWildcard() {
let path = "Tests/*Tests.swift"
let directory = URL(fileURLWithPath: #file)
.deletingLastPathComponent().deletingLastPathComponent()
XCTAssertEqual(try matchGlobs(expandGlobs(path, in: directory.path), in: directory.path).count, 15)
XCTAssertEqual(try matchGlobs(expandGlobs(path, in: directory.path), in: directory.path).count, 16)
}

func testSingleWildcardDoesNotMatchDirectorySlash() {
Expand Down
23 changes: 0 additions & 23 deletions Tests/InferenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,6 @@ import XCTest
@testable import SwiftFormat

class InferenceTests: XCTestCase {
static let files: [String] = {
var files = [String]()
let inputURL = URL(fileURLWithPath: #file)
.deletingLastPathComponent().deletingLastPathComponent()

_ = enumerateFiles(withInputURL: inputURL) { url, _, _ in
{
if let source = try? String(contentsOf: url) {
files.append(source)
}
}
}
return files
}()

func testInferOptionsForProject() {
let files = InferenceTests.files
let tokens = files.flatMap { tokenize($0) }
let options = Options(formatOptions: inferFormatOptions(from: tokens))
let arguments = serialize(options: options, excludingDefaults: true, separator: " ")
XCTAssertEqual(arguments, "--binarygrouping none --decimalgrouping none --hexgrouping none --octalgrouping none --semicolons never")
}

// MARK: indent

func testInferIndentLevel() {
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftFormatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SwiftFormatTests: XCTestCase {
return { files.append(inputURL) }
}
XCTAssertEqual(errors.count, 0)
XCTAssertEqual(files.count, 71)
XCTAssertEqual(files.count, 72)
}

func testInputFilesMatchOutputFilesForSameOutput() {
Expand All @@ -78,7 +78,7 @@ class SwiftFormatTests: XCTestCase {
return { files.append(inputURL) }
}
XCTAssertEqual(errors.count, 0)
XCTAssertEqual(files.count, 71)
XCTAssertEqual(files.count, 72)
}

func testInputFileNotEnumeratedWhenExcluded() {
Expand Down
57 changes: 57 additions & 0 deletions Tests/ZRegressionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// ZRegressionTests.swift
// SwiftFormatTests
//
// Created by Nick Lockwood on 28/03/2024.
// Copyright © 2024 Nick Lockwood. All rights reserved.
//

import XCTest
@testable import SwiftFormat

private let projectDirectory = URL(fileURLWithPath: #file)
.deletingLastPathComponent().deletingLastPathComponent()

private let projectFiles: [String] = {
var files = [String]()
_ = enumerateFiles(withInputURL: projectDirectory) { url, _, _ in
{
if let source = try? String(contentsOf: url) {
files.append(source)
}
}
}
return files
}()

// Note: Z prefix ensures these run last
class ZRegressionTests: XCTestCase {
// MARK: infererence

func testInferOptionsForProject() {
let tokens = projectFiles.flatMap { tokenize($0) }
let options = Options(formatOptions: inferFormatOptions(from: tokens))
let arguments = serialize(options: options, excludingDefaults: true, separator: " ")
XCTAssertEqual(arguments, "--binarygrouping none --decimalgrouping none --hexgrouping none --octalgrouping none --semicolons never")
}

// MARK: snapshot/regression tests

func testRegressionSuite() {
CLI.print = { message, _ in
Swift.print(message)
}
// NOTE: to update regression suite, run again without `--lint` argument
XCTAssertEqual(CLI.run(in: projectDirectory.path, with: "Sources,Tests,Snapshots --unexclude Snapshots --symlinks follow --cache ignore --lint"), .ok)
}

func testRegressionSuiteNotDisabled() throws {
let commandLineTests = try String(contentsOf: URL(fileURLWithPath: #file))
let range = try XCTUnwrap(
commandLineTests.range(of: "testRegressionSuiteNotDisabled()")
)
XCTAssert(commandLineTests[..<range.lowerBound].contains("""
with: "Sources,Tests,Snapshots --unexclude Snapshots --symlinks follow --cache ignore --lint")
"""))
}
}

0 comments on commit ca70962

Please sign in to comment.