diff --git a/Sources/Options.swift b/Sources/Options.swift index 4034824c0..cbe3cb6bb 100644 --- a/Sources/Options.swift +++ b/Sources/Options.swift @@ -263,7 +263,7 @@ public enum FileHeaderMode: Equatable, RawRepresentable, ExpressibleByStringLite } } -public struct ReplacementOptions { +public struct ReplacementOptions: CustomStringConvertible { var dateFormat: DateFormat var timeZone: FormatTimeZone @@ -275,9 +275,13 @@ public struct ReplacementOptions { init(_ options: FormatOptions) { self.init(dateFormat: options.dateFormat, timeZone: options.timeZone) } + + public var description: String { + "\(dateFormat)@\(timeZone)" + } } -public enum ReplacementType: Equatable { +public enum ReplacementType: Equatable, CustomStringConvertible { case constant(String) case dynamic((FileInfo, ReplacementOptions) -> String?) @@ -305,6 +309,15 @@ public enum ReplacementType: Equatable { return fn(info, options) } } + + public var description: String { + switch self { + case let .constant(value): + return value + case .dynamic: + return "dynamic" + } + } } /// File info, used for constructing header comments @@ -338,7 +351,8 @@ public struct FileInfo: Equatable, CustomStringConvertible { } public var description: String { - replacements.enumerated() + replacements + .sorted(by: { $0.key.rawValue < $1.key.rawValue }) .map { "\($0)=\($1)" } .joined(separator: ";") } @@ -916,7 +930,15 @@ public struct FormatOptions: CustomStringConvertible { public var description: String { let allowedCharacters = CharacterSet.newlines.inverted return Mirror(reflecting: self).children.compactMap { child in - let value = (child.value as? Set).map { $0.sorted as Any } ?? child.value + var value = child.value + switch value { + case let array as [String]: + value = array.joined(separator: ",") + case let set as Set: + value = set.sorted().joined(separator: ",") + default: + break + } return "\(value);".addingPercentEncoding(withAllowedCharacters: allowedCharacters) }.joined() } diff --git a/Tests/ZRegressionTests.swift b/Tests/ZRegressionTests.swift index 3933bd0c5..5213afb23 100644 --- a/Tests/ZRegressionTests.swift +++ b/Tests/ZRegressionTests.swift @@ -37,6 +37,26 @@ class ZRegressionTests: XCTestCase { // MARK: snapshot/regression tests + func testCache() { + CLI.print = { message, _ in + Swift.print(message) + } + // NOTE: to update regression suite, run again without `--lint` argument + let result = CLI.run(in: projectDirectory.path, with: "Tests --cache clear --lint") + XCTAssertEqual(result, .ok) + + // Test cache + if result == .ok { + var messages = [String]() + CLI.print = { message, _ in + Swift.print(message) + messages.append(message) + } + XCTAssertEqual(CLI.run(in: projectDirectory.path, with: "Tests --symlinks follow --lint --verbose"), .ok) + XCTAssert(messages.contains("-- no changes (cached)")) + } + } + func testRegressionSuite() { CLI.print = { message, _ in Swift.print(message)