Skip to content

Commit 6d59b51

Browse files
committed
feat: add testing framework and update build workflow for enhanced testing capabilities
1 parent 6d9198f commit 6d59b51

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

.github/workflows/build.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ jobs:
5252
with:
5353
dotnet-version: '9.0.x'
5454

55+
- name: Setup tools
56+
run: |
57+
npm install -g bats
58+
59+
- name: Tests
60+
env:
61+
DATABASE_HOST: localhost
62+
DATABASE_PORT: 5433
63+
run: |
64+
mkdir test-results
65+
bats . --verbose-run --print-output-on-failure --report-formatter junit --output test-results
66+
ls -lah test-results
67+
5568
- name: Restore dependencies
5669
run: dotnet restore
5770

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
bin
22
obj
3+
current.log
4+
test-results

Tests.fsx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#load "Sprout.fs"
2+
3+
open Sprout
4+
5+
let s1 = describe "Suite 1" {}
6+
let s2 = describe "Suite 2" {
7+
beforeEach {
8+
debug "Before each test in Suite 2"
9+
}
10+
11+
it "should pass in Suite 2" {
12+
info "This test passes in Suite 2"
13+
}
14+
}
15+
runTestSuite (describe "Main Suite" { s1; s2 })
16+
17+
let suite = describe "A larger test suite" {
18+
beforeEach {
19+
debug "Before each test"
20+
}
21+
22+
afterEach {
23+
debug "After each test"
24+
}
25+
26+
it "should pass" {
27+
info "This test passes"
28+
}
29+
30+
it "should fail" {
31+
info "This test fails"
32+
failwith "Intentional failure"
33+
}
34+
35+
pending "This is a pending test"
36+
37+
describe "Nested suite" {
38+
it "should also pass" {
39+
info "Nested test passes"
40+
}
41+
}
42+
43+
describe "Arithmetic" {
44+
describe "Addition" {
45+
it "should add two numbers correctly" {
46+
let result = 2 + 2
47+
result |> shouldEqual 4
48+
}
49+
50+
it "should handle negative numbers" {
51+
let result = -1 + -1
52+
result |> shouldEqual -2
53+
}
54+
}
55+
56+
describe "Faulty Addition" {
57+
it "should fail when adding incorrect numbers" {
58+
let result = 2 + 2
59+
result |> shouldEqual 5
60+
}
61+
}
62+
}
63+
}
64+
65+
runTestSuite suite

expected.log

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Main Suite
2+
Suite 1
3+
Suite 2
4+
Before each test in Suite 2
5+
This test passes in Suite 2
6+
 ✅ passed: should pass in Suite 2
7+
All tests passed!
8+
Summary: 1 passed, 0 failed, 0 pending
9+
Total time: 00:00:00.0045414
10+
A larger test suite
11+
Before each test
12+
This test passes
13+
After each test
14+
 ✅ passed: should pass
15+
Before each test
16+
This test fails
17+
After each test
18+
 ❌ failed: should fail - Intentional failure
19+
Before each test
20+
After each test
21+
 ❔ pending: This is a pending test
22+
Nested suite
23+
Before each test
24+
Nested test passes
25+
After each test
26+
 ✅ passed: should also pass
27+
Arithmetic
28+
Addition
29+
Before each test
30+
After each test
31+
 ✅ passed: should add two numbers correctly
32+
Before each test
33+
After each test
34+
 ✅ passed: should handle negative numbers
35+
Faulty Addition
36+
Before each test
37+
After each test
38+
 ❌ failed: should fail when adding incorrect numbers - Expected 5 but got 4
39+
There were 2 test failures:
40+
- A larger test suite / should fail - Intentional failure
41+
- A larger test suite / Arithmetic / Faulty Addition / should fail when adding incorrect numbers - Expected 5 but got 4
42+
Summary: 4 passed, 2 failed, 1 pending
43+
Total time: 00:00:00.0034939

test.bats

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
@test "Tests.fsx" {
4+
dotnet fsi Tests.fsx > current.log
5+
run diff <(cat expected.log | grep -v "Total time") <(cat current.log | grep -v "Total time")
6+
[ "$status" -eq 0 ]
7+
printf 'Lines:\n'
8+
printf 'lines %s\n' "${lines[@]}" >&2
9+
printf 'output %s\n' "${output[@]}" >&2
10+
}

0 commit comments

Comments
 (0)