Skip to content

Commit

Permalink
Fix cache
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Jul 22, 2024
1 parent e20ba85 commit de7ec22
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
30 changes: 26 additions & 4 deletions Sources/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public enum FileHeaderMode: Equatable, RawRepresentable, ExpressibleByStringLite
}
}

public struct ReplacementOptions {
public struct ReplacementOptions: CustomStringConvertible {
var dateFormat: DateFormat
var timeZone: FormatTimeZone

Expand All @@ -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?)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: ";")
}
Expand Down Expand Up @@ -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<AnyHashable>).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<String>:
value = set.sorted().joined(separator: ",")
default:
break
}
return "\(value);".addingPercentEncoding(withAllowedCharacters: allowedCharacters)
}.joined()
}
Expand Down
20 changes: 20 additions & 0 deletions Tests/ZRegressionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit de7ec22

Please sign in to comment.