Skip to content

Commit b6ff6e9

Browse files
committed
init
0 parents  commit b6ff6e9

File tree

16 files changed

+942
-0
lines changed

16 files changed

+942
-0
lines changed

.github/workflows/CI.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This workflow will build a Swift project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift
3+
4+
name: CI
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: macos-latest
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Build
20+
run: swift build -v
21+
- name: Run tests
22+
run: swift test -v
23+

.github/workflows/docc.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: docc
2+
on:
3+
push:
4+
branches: ["main"]
5+
permissions:
6+
contents: read
7+
pages: write
8+
id-token: write
9+
concurrency:
10+
group: "pages"
11+
cancel-in-progress: true
12+
jobs:
13+
pages:
14+
environment:
15+
name: github-pages
16+
url: ${{ steps.deployment.outputs.page_url }}
17+
runs-on: macos-12
18+
steps:
19+
- name: git checkout
20+
uses: actions/checkout@v3
21+
- name: docbuild
22+
run: |
23+
xcodebuild docbuild -scheme Test \
24+
-derivedDataPath /tmp/docbuild \
25+
-destination 'generic/platform=iOS';
26+
$(xcrun --find docc) process-archive \
27+
transform-for-static-hosting /tmp/docbuild/Build/Products/Debug-iphoneos/Test.doccarchive \
28+
--hosting-base-path Test \
29+
--output-path docs;
30+
echo "<script>window.location.href += \"/documentation/test\"</script>" > docs/index.html;
31+
- name: artifacts
32+
uses: actions/upload-pages-artifact@v1
33+
with:
34+
path: 'docs'
35+
- name: deploy
36+
id: deployment
37+
uses: actions/deploy-pages@v1
38+

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/
6+
DerivedData/
7+
.swiftpm/config/registries.json
8+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
9+
.netrc

Package.resolved

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// swift-tools-version: 5.7
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "Test",
8+
platforms: [
9+
.iOS(.v14),
10+
.macOS(.v11),
11+
.watchOS(.v7),
12+
.tvOS(.v14)
13+
],
14+
products: [
15+
.library(
16+
name: "Test",
17+
targets: ["Test"]),
18+
],
19+
dependencies: [
20+
.package(url: "https://github.com/0xOpenBytes/t", from: "1.0.0"),
21+
.package(url: "https://github.com/0xLeif/Scribe", from: "1.3.0"),
22+
.package(url: "https://github.com/0xLeif/Plugin", from: "2.0.0")
23+
],
24+
targets: [
25+
.target(
26+
name: "Test",
27+
dependencies: [
28+
"t",
29+
"Scribe",
30+
"Plugin"
31+
]
32+
),
33+
.testTarget(
34+
name: "TestTests",
35+
dependencies: ["Test"]
36+
)
37+
]
38+
)

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Test
2+
3+
*Expect and assert*
4+
5+
## What is `Test`?
6+
7+
`Test` is a simple testing function that allows you to create test suites with multiple steps, expectations, and assertions. You can specify a name for the test suite, an instance of the `Tester` class to be used for running the tests, and a closure that contains the test steps.
8+
9+
## Where can `Test` be used?
10+
11+
`Test` can be used anywhere! `Test` can be used to test quickly inside a function to make sure something is working as expected. It is especially useful when you want to test a complex piece of code with multiple steps and assertions. `Test` can even be used for your unit tests!
12+
13+
## Examples
14+
15+
### Simple test with assertions
16+
17+
```swift
18+
try await Test(named: "Test someMethod()") { tester in
19+
try tester.assert(SomeClass.someMethod())
20+
try await tester.assertNoThrows(try await SomeClass.someOtherMethod())
21+
try tester.assert(SomeClass.someBooleanValue, isEqualTo: false)
22+
}
23+
```
24+
25+
### Test with expectations
26+
27+
```swift
28+
try Test(named: "Test someMethod() with expectations") { tester in
29+
try Expect("First step should succeed") {
30+
try SomeClass.someMethod()
31+
}
32+
33+
tester.logInfo("Just finished first step")
34+
35+
try Expect("Second step should succeed") {
36+
try SomeClass.someOtherMethod()
37+
}
38+
39+
tester.logWarning("Something unexpected happened during the second step")
40+
41+
try Expect("Final assertion should be true") {
42+
try tester.assert(SomeClass.someBooleanValue)
43+
}
44+
45+
tester.logSuccess("All steps and assertions passed!")
46+
}
47+
```

Sources/Test/Expect.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import t
2+
3+
/**
4+
The `Expect` function is used to define a test expectation within a `Test` function. The expectation closure contains the code that should succeed and produce the expected result.
5+
6+
- Parameters:
7+
- description: A string describing the expectation.
8+
- expectation: A closure that contains the code to test the expectation.
9+
*/
10+
public func Expect(
11+
_ description: String? = nil,
12+
expectation: @escaping () throws -> Void
13+
) throws {
14+
try t.expect(description, expectation: expectation)
15+
}
16+
17+
/**
18+
The `Expect` function is used to define a test expectation within a `Test` function. The expectation closure contains the code that should succeed and produce the expected result.
19+
20+
- Parameters:
21+
- description: A string describing the expectation.
22+
- expectation: A closure that contains the code to test the expectation.
23+
*/
24+
public func Expect(
25+
_ description: String? = nil,
26+
expectation: @escaping () async throws -> Void
27+
) async throws {
28+
try await t.expect(description, expectation: expectation)
29+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import t
2+
import Scribe
3+
4+
/**
5+
The `TestConfiguration` enum provides a global configuration for tests.
6+
7+
Use this enum to customize the logger and scribe for the test framework.
8+
9+
Example usage:
10+
11+
TestConfiguration.logger = { print($0) }
12+
TestConfiguration.scribe = Scribe(label: "Custom Scribe")
13+
14+
*/
15+
public enum TestConfiguration {
16+
/**
17+
A closure that receives a string and logs it. This is used by the framework to log messages when tests run.
18+
19+
By default, the logger is set to `t.logger` from the `t` library.
20+
21+
- Note: To change the logger, set `TestConfiguration.logger`.
22+
23+
Example usage:
24+
25+
TestConfiguration.logger = { print($0) }
26+
*/
27+
public static var logger: (String) -> Void {
28+
get { t.logger }
29+
set { t.logger = newValue }
30+
}
31+
32+
/**
33+
The scribe used by the test framework.
34+
35+
By default, the scribe is set to a new instance of `Scribe` with a label of "Test.Scribe".
36+
37+
- Note: To change the scribe, set `TestConfiguration.scribe`.
38+
39+
Example usage:
40+
41+
TestConfiguration.scribe = Scribe(label: "Custom Scribe")
42+
43+
*/
44+
public static var scribe: Scribe = Scribe(label: "Test.Scribe")
45+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Plugin
2+
3+
/**
4+
The `TestPlugin` protocol defines a contract for plugins that can be used to extend the behavior of the `Tester` class.
5+
6+
`TestPlugin` extends the `ImmutablePlugin` protocol, which allows the plugin to be treated as an immutable object.
7+
8+
`TestPlugin` is used for conveince when creating a `Plugin` for a `Tester`.
9+
*/
10+
public protocol TestPlugin: ImmutablePlugin { }

0 commit comments

Comments
 (0)