forked from realm/SwiftLint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Inline test failure messages (realm#3040)
* Add Example wrapper in order to display test failures inline when running in Xcode. * Stop using Swift 5.1-only features so we can compile on Xcode 10.2. * Wrap strings in Example. * Add Changelog entry. * Wrap all examples in Example struct. * Better and more complete capturing of line numbers. * Fix broken test. * Better test traceability. * Address or disable linting warnings. * Add documentation comments. * Disable linter for a few cases. * Limit mutability and add copy-and-mutate utility functions. * Limit scope of mutability.
- Loading branch information
1 parent
ed54fd6
commit fcf8486
Showing
246 changed files
with
6,609 additions
and
5,684 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/// Captures code and context information for an example of a triggering or | ||
/// non-triggering style | ||
public struct Example { | ||
/// The contents of the example | ||
public private(set) var code: String | ||
/// The path to the file where the example was created | ||
public private(set) var file: StaticString | ||
/// The line in the file where the example was created | ||
public var line: UInt | ||
} | ||
|
||
public extension Example { | ||
/// Create a new Example with the specified code, file, and line | ||
/// - Parameters: | ||
/// - code: The contents of the example | ||
/// - file: The path to the file where the example is located. | ||
/// Defaults to the file where this initializer is called. | ||
/// - line: The line in the file where the example is located. | ||
/// Defaults to the line where this initializer is called. | ||
init(_ code: String, file: StaticString = #file, line: UInt = #line) { | ||
self.code = code | ||
self.file = file | ||
self.line = line | ||
} | ||
|
||
/// Returns the same example, but with the `code` that is passed in | ||
/// - Parameter code: the new code to use in the modified example | ||
func with(code: String) -> Example { | ||
var new = self | ||
new.code = code | ||
return new | ||
} | ||
|
||
/// Returns a copy of the Example with all instances of the "↓" character removed. | ||
func removingViolationMarkers() -> Example { | ||
return with(code: code.replacingOccurrences(of: "↓", with: "")) | ||
} | ||
} | ||
|
||
extension Example: Hashable { | ||
public static func == (lhs: Example, rhs: Example) -> Bool { | ||
// Ignoring file/line metadata because two Examples could represent | ||
// the same idea, but captured at two different points in the code | ||
return lhs.code == rhs.code | ||
} | ||
|
||
public func hash(into hasher: inout Hasher) { | ||
// Ignoring file/line metadata because two Examples could represent | ||
// the same idea, but captured at two different points in the code | ||
hasher.combine(code) | ||
} | ||
} | ||
|
||
extension Example: Comparable { | ||
public static func < (lhs: Example, rhs: Example) -> Bool { | ||
return lhs.code < rhs.code | ||
} | ||
} |
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
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
Oops, something went wrong.