-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b0730b
commit ca70962
Showing
6 changed files
with
65 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
""")) | ||
} | ||
} |