GitXplorerGitXplorer
k

swift-checkit

public
20 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
f2b91bd4ec068a0ab8a73051c0077d1e1b614b43

Disable BidirectionalCollection in-place index formation tests, due to SR-13874

kkarwa committed 4 years ago
Unverified
85f9ce34dd25e8f7fb8b07a67189876ab94a607b

Disable uncatchable test

kkarwa committed 4 years ago
Unverified
d6a3380bb939df0fddbaee1f7f32dc1b50d518c8

Add some basic BinaryFloatingPoint checks, thanks to Jens Persson (https://forums.swift.org/u/jens/)

kkarwa committed 5 years ago
Unverified
8835800e0a071e1569dd05586883e05d58c053de

Update README

kkarwa committed 5 years ago
Verified
e08c3a2ec0a3f0cd1963ccd33ad106329a86f0c3

Create LICENSE

kkarwa committed 5 years ago
Unverified
c68bde5a36176e5189249c8d39b9ff7209989679

Add SinglePassSequenceChecker

kkarwa committed 5 years ago

README

The README file for this repository.

swift-checkit

Swift-checkit is a library containing validators which exercise common protocols.

This all started because I hit a bug recently: on one of my custom collections, incrementing startIndex by count returned nil, rather than the expected endIndex. I never noticed this before, because all of my real-world code incremented indices by +/-1, and never in steps larger than that. Nonetheless, there were expected, documented semantics and generic code was relying on that.

Swift's protocols aren't just bags of syntax; there is some expected behaviour attached to each of them. Sometimes those expectations can be reflected in the type-system, but sometimes they have to be explained in documentation and left to the programmer. That's fine - but as software becomes more complex, it's easy to make changes which accidentally violate some subtle semantics of the protocol. That's why we write tests.

Swift-checkit has some helpful pre-made tests to make that easier.

Installation

Installation is via the Swift Package Manager. Simply add the package to your Package.swift, and add "Checkit" as a dependency for your test targets:

// Package.swift

let package = Package(...
    dependencies: [
        .package(url: "https://github.com/karwa/swift-checkit.git", .branch("master"))
    ],
    targets: [
        .testTarget(name: "MyTests", dependencies: ["Checkit"]),
    ]
    ...
)

Now all you need to write is:

// MyTests.swift
import Checkit

and you're good to start using the validators. How about checking if your custom Collection really conforms to the protocol? Or whether your Sequence-constrained algorithm really handles a single-pass Sequence?

func testCollectionSemantics() {
  let myCustomCollection = MyCollection(...)
  CollectionChecker.check(myCustomCollection)
}

// in project:
// func myAlgorithm<S: Sequence>(with: S) { ... }

func testAlgorithm() {
  SinglePassSequenceChecker.check(0..<5) { sequence in myAlgorithm(sequence) }
}

Contributing

Contributions welcome! Feel free to fork/add/send PRs for new checks and checkers!