Skip to content

Commit 3c5f002

Browse files
committed
WIP #83 TestScript
1 parent 002ea5b commit 3c5f002

File tree

7 files changed

+107
-46
lines changed

7 files changed

+107
-46
lines changed

.github/workflows/test.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Run tests
2+
on:
3+
push:
4+
branches:
5+
- '**'
6+
pull_request:
7+
branches:
8+
- '**'
9+
10+
jobs:
11+
test:
12+
name: Test on ${{ matrix.os }}
13+
strategy:
14+
matrix:
15+
include:
16+
- os: ubuntu-latest
17+
arch: amd64
18+
- os: ubuntu-latest
19+
arch: arm64
20+
- os: macos-latest
21+
arch: amd64
22+
- os: macos-latest
23+
arch: arm64
24+
- os: windows-latest
25+
arch: amd64
26+
runs-on: ${{ matrix.os }}
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- name: Set up Go
31+
uses: actions/setup-go@v5
32+
with:
33+
go-version: 'stable'
34+
architecture: ${{ matrix.arch }}
35+
36+
- name: Test
37+
run: go test ./...

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ deps:
3838
.PHONY: test
3939
test:
4040
$(info Running tests...)
41-
go test ./...
41+
go test -short ./...
4242

4343
# Build launchr
4444
.PHONY: build

main_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package launchr
2+
3+
import (
4+
"testing"
5+
6+
"github.com/rogpeppe/go-internal/testscript"
7+
)
8+
9+
func TestMain(m *testing.M) {
10+
testscript.Main(m, map[string]func(){
11+
"launchr": RunAndExit,
12+
})
13+
}
14+
15+
// TODO: Implement test groups build/runtime/unit
16+
// TestScriptBuild tests how binary builds and outputs version.
17+
func TestScriptBuild(t *testing.T) {
18+
if testing.Short() {
19+
t.Skip("skipping test in short mode.")
20+
}
21+
testscript.Run(t, testscript.Params{
22+
Dir: "test/testdata/build",
23+
RequireExplicitExec: true,
24+
RequireUniqueNames: true,
25+
Setup: func(env *testscript.Env) error {
26+
repoPath := MustAbs("./")
27+
env.Vars = append(
28+
env.Vars,
29+
"REPO_PATH="+repoPath,
30+
"CORE_PKG="+PkgPath,
31+
)
32+
return nil
33+
},
34+
})
35+
}
36+
37+
func TestScriptCommon(t *testing.T) {
38+
if testing.Short() {
39+
t.Skip("skipping test in short mode.")
40+
}
41+
t.Parallel()
42+
type testCase struct {
43+
name string
44+
files []string
45+
}
46+
commonDir := "test/testdata/common"
47+
tests := []testCase{
48+
{"action discovery basic", []string{commonDir + "/discovery_basic.txtar"}},
49+
{"action discovery config naming", []string{commonDir + "/discovery_config_naming.txtar"}},
50+
}
51+
for _, tt := range tests {
52+
tt := tt
53+
t.Run(tt.name, func(t *testing.T) {
54+
t.Parallel()
55+
testscript.Run(t, testscript.Params{
56+
Files: tt.files,
57+
RequireExplicitExec: true,
58+
RequireUniqueNames: true,
59+
ContinueOnError: true,
60+
})
61+
})
62+
}
63+
64+
}

test/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Integration tests
2+
3+
This directory contains integration tests and their test data.

test/t_test.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

test/testdata/common/discovery_basic.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
exec launchr --help
22

33
# Actions are grouped and sorted.
4-
stdout '^\s+Actions:\n\s+bar\s+$'
4+
stdout '^\s+Actions:\n\s+bar\s+'
55

66
# Valid discovered actions
77
stdout '^\s+bar\s+bar$'

test/testdata/common/processors.txtar

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Test processors

0 commit comments

Comments
 (0)