diff options
author | EuAndreh <eu@euandre.org> | 2024-08-14 17:11:33 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-08-14 17:11:33 -0300 |
commit | 80cdec3927ea866aea27ec356ae1d3f525ae94d7 (patch) | |
tree | efd74d3eb532da8b34449771aacd9696c807a051 /tests | |
parent | Makefile: Reorder CLI args to go(1) (diff) | |
download | papod-80cdec3927ea866aea27ec356ae1d3f525ae94d7.tar.gz papod-80cdec3927ea866aea27ec356ae1d3f525ae94d7.tar.xz |
Use "go tool" to build project
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/integration.sh | 4 | ||||
-rw-r--r-- | tests/main.go | 7 | ||||
-rw-r--r-- | tests/papod.go (renamed from tests/lib_test.go) | 148 |
3 files changed, 98 insertions, 61 deletions
diff --git a/tests/integration.sh b/tests/integration.sh new file mode 100755 index 0000000..fcb62ca --- /dev/null +++ b/tests/integration.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu + +exit diff --git a/tests/main.go b/tests/main.go new file mode 100644 index 0000000..f32854e --- /dev/null +++ b/tests/main.go @@ -0,0 +1,7 @@ +package main + +import "papod" + +func main() { + papod.MainTest() +} diff --git a/tests/lib_test.go b/tests/papod.go index 67fbb40..af2a5f7 100644 --- a/tests/lib_test.go +++ b/tests/papod.go @@ -1,16 +1,16 @@ -package papod_test +package papod import ( "bufio" "database/sql" "errors" + "os" "reflect" "strings" "testing" + "testing/internal/testdeps" - g "euandre.org/gobang/src" - - "euandre.org/papod/src" + g "gobang" ) @@ -86,7 +86,7 @@ func TestSplitOnCRLF(t *testing.T) { for i, entry := range table { var given []string scanner := bufio.NewScanner(strings.NewReader(entry.input)) - scanner.Split(papod.SplitOnCRLF) + scanner.Split(SplitOnCRLF) for scanner.Scan() { given = append(given, scanner.Text()) } @@ -117,7 +117,7 @@ func TestSplitOnRawMessage(t *testing.T) { for i, entry := range table { var given []string scanner := bufio.NewScanner(strings.NewReader(entry.input)) - scanner.Split(papod.SplitOnRawMessage) + scanner.Split(SplitOnRawMessage) for scanner.Scan() { given = append(given, scanner.Text()) } @@ -131,180 +131,180 @@ func TestSplitOnRawMessage(t *testing.T) { func TestParseMessageParams(t *testing.T) { type tableT struct { input string - expected papod.MessageParams + expected MessageParams } table := []tableT { { "", - papod.MessageParams { + MessageParams { Middle: []string { }, Trailing: "", }, }, { " ", - papod.MessageParams { + MessageParams { Middle: []string { }, Trailing: "", }, }, { " :", - papod.MessageParams { + MessageParams { Middle: []string { }, Trailing: "", }, }, { " : ", - papod.MessageParams { + MessageParams { Middle: []string { }, Trailing: " ", }, }, { ": ", - papod.MessageParams { + MessageParams { Middle: []string { ":" }, Trailing: "", }, }, { ": ", - papod.MessageParams { + MessageParams { Middle: []string { ":" }, Trailing: "", }, }, { " : ", - papod.MessageParams { + MessageParams { Middle: []string { }, Trailing: " ", }, }, { " :", - papod.MessageParams { + MessageParams { Middle: []string { }, Trailing: "", }, }, { " :", - papod.MessageParams { + MessageParams { Middle: []string { }, Trailing: "", }, }, { "a", - papod.MessageParams { + MessageParams { Middle: []string { "a" }, Trailing: "", }, }, { "ab", - papod.MessageParams { + MessageParams { Middle: []string { "ab" }, Trailing: "", }, }, { "a b", - papod.MessageParams { + MessageParams { Middle: []string { "a", "b" }, Trailing: "", }, }, { "a b c", - papod.MessageParams { + MessageParams { Middle: []string { "a", "b", "c" }, Trailing: "", }, }, { "a b:c", - papod.MessageParams { + MessageParams { Middle: []string { "a", "b:c" }, Trailing: "", }, }, { "a b:c:", - papod.MessageParams { + MessageParams { Middle: []string { "a", "b:c:" }, Trailing: "", }, }, { "a b :c", - papod.MessageParams { + MessageParams { Middle: []string { "a", "b" }, Trailing: "c", }, }, { "a b :c:", - papod.MessageParams { + MessageParams { Middle: []string { "a", "b" }, Trailing: "c:", }, }, { "a b :c ", - papod.MessageParams { + MessageParams { Middle: []string { "a", "b" }, Trailing: "c ", }, }, { "a b : c", - papod.MessageParams { + MessageParams { Middle: []string { "a", "b" }, Trailing: " c", }, }, { "a b : c ", - papod.MessageParams { + MessageParams { Middle: []string { "a", "b" }, Trailing: " c ", }, }, { "a b : c :", - papod.MessageParams { + MessageParams { Middle: []string { "a", "b" }, Trailing: " c :", }, }, { "a b : c : ", - papod.MessageParams { + MessageParams { Middle: []string { "a", "b" }, Trailing: " c : ", }, }, { "a b : c :d", - papod.MessageParams { + MessageParams { Middle: []string { "a", "b" }, Trailing: " c :d", }, }, { "a b : c :d ", - papod.MessageParams { + MessageParams { Middle: []string { "a", "b" }, Trailing: " c :d ", }, }, { "a b : c : d ", - papod.MessageParams { + MessageParams { Middle: []string { "a", "b" }, Trailing: " c : d ", }, @@ -312,7 +312,7 @@ func TestParseMessageParams(t *testing.T) { } for i, entry := range table { - given := papod.ParseMessageParams(entry.input) + given := ParseMessageParams(entry.input) assertEqualI(t, i, given, entry.expected) } } @@ -320,14 +320,14 @@ func TestParseMessageParams(t *testing.T) { func TestParseMessage(t *testing.T) { type tableTOK struct { input string - expected papod.Message + expected Message } tableOK := []tableTOK {{ "NICK joebloe ", - papod.Message { + Message { Prefix: "", Command: "NICK", - Params: papod.MessageParams { + Params: MessageParams { Middle: []string { "joebloe" }, Trailing: "", }, @@ -335,10 +335,10 @@ func TestParseMessage(t *testing.T) { }, }, { "USER joebloe 0.0.0.0 joe :Joe Bloe", - papod.Message { + Message { Prefix: "", Command: "USER", - Params: papod.MessageParams { + Params: MessageParams { Middle: []string { "joebloe", "0.0.0.0", "joe", }, @@ -348,10 +348,10 @@ func TestParseMessage(t *testing.T) { }, }, { ":pre USER joebloe 0.0.0.0 joe :Joe Bloe", - papod.Message { + Message { Prefix: "pre", Command: "USER", - Params: papod.MessageParams { + Params: MessageParams { Middle: []string { "joebloe", "0.0.0.0", "joe", }, @@ -361,10 +361,10 @@ func TestParseMessage(t *testing.T) { }, }, { ":pre USER joebloe 0.0.0.0 joe : Joe Bloe ", - papod.Message { + Message { Prefix: "pre", Command: "USER", - Params: papod.MessageParams { + Params: MessageParams { Middle: []string { "joebloe", "0.0.0.0", "joe", }, @@ -374,10 +374,10 @@ func TestParseMessage(t *testing.T) { }, }, { ":pre USER joebloe: 0:0:0:1 joe::a: : Joe Bloe ", - papod.Message { + Message { Prefix: "pre", Command: "USER", - Params: papod.MessageParams { + Params: MessageParams { Middle: []string { "joebloe:", "0:0:0:1", "joe::a:", }, @@ -387,10 +387,10 @@ func TestParseMessage(t *testing.T) { }, }, { ":pre USER :Joe Bloe", - papod.Message { + Message { Prefix: "pre", Command: "USER", - Params: papod.MessageParams { + Params: MessageParams { Middle: []string { }, Trailing: "Joe Bloe", }, @@ -398,10 +398,10 @@ func TestParseMessage(t *testing.T) { }, }, { ":pre USER : Joe Bloe", - papod.Message { + Message { Prefix: "pre", Command: "USER", - Params: papod.MessageParams { + Params: MessageParams { Middle: []string { }, Trailing: " Joe Bloe", }, @@ -409,10 +409,10 @@ func TestParseMessage(t *testing.T) { }, }, { ":pre USER : Joe Bloe", - papod.Message { + Message { Prefix: "pre", Command: "USER", - Params: papod.MessageParams { + Params: MessageParams { Middle: []string { }, Trailing: " Joe Bloe", }, @@ -420,10 +420,10 @@ func TestParseMessage(t *testing.T) { }, }, { ":pre USER : ", - papod.Message { + Message { Prefix: "pre", Command: "USER", - Params: papod.MessageParams { + Params: MessageParams { Middle: []string { }, Trailing: " ", }, @@ -431,10 +431,10 @@ func TestParseMessage(t *testing.T) { }, }, { ":pre USER :", - papod.Message { + Message { Prefix: "pre", Command: "USER", - Params: papod.MessageParams { + Params: MessageParams { Middle: []string { }, Trailing: "", }, @@ -443,7 +443,7 @@ func TestParseMessage(t *testing.T) { }} for i, entry := range tableOK { - given, err := papod.ParseMessage(entry.input) + given, err := ParseMessage(entry.input) errorIf(t, err) assertEqualI(t, i, given, entry.expected) } @@ -470,7 +470,7 @@ func TestParseMessage(t *testing.T) { } for i, entry := range tableError { - _, given := papod.ParseMessage(entry.input) + _, given := ParseMessage(entry.input) assertEqualI(t, i, given, entry.expected) } } @@ -485,7 +485,7 @@ func TestInitMigrations(t *testing.T) { assertEqual(t, err.Error(), "no such table: migrations") for i := 0; i < 5; i++ { - papod.InitMigrations(db) + InitMigrations(db) rows, err := db.Query(query) g.FatalIf(err) assertEqual(t, rows.Next(), false) @@ -497,9 +497,9 @@ func TestPendingMigrations(t *testing.T) { db, err := sql.Open("sqlite3", ":memory:") g.FatalIf(err) - papod.InitMigrations(db) - pending1 := papod.PendingMigrations(db) - pending2 := papod.PendingMigrations(db) + InitMigrations(db) + pending1 := PendingMigrations(db) + pending2 := PendingMigrations(db) assertEqual(t, pending1, pending2) } @@ -509,6 +509,32 @@ func TestRunMigrations(t *testing.T) { g.FatalIf(err) for i := 0; i < 5; i++ { - papod.RunMigrations(db) + RunMigrations(db) } } + + + +func MainTest() { + tests := []testing.InternalTest { + { "TestSplitOnCRLF", TestSplitOnCRLF }, + { "TestSplitOnRawMessage", TestSplitOnRawMessage }, + { "TestParseMessageParams", TestParseMessageParams }, + { "TestParseMessage", TestParseMessage }, + { "TestInitMigrations", TestInitMigrations }, + { "TestPendingMigrations", TestPendingMigrations }, + { "TestRunMigrations", TestRunMigrations }, + } + + benchmarks := []testing.InternalBenchmark {} + fuzzTargets := []testing.InternalFuzzTarget {} + examples := []testing.InternalExample {} + m := testing.MainStart( + testdeps.TestDeps {}, + tests, + benchmarks, + fuzzTargets, + examples, + ) + os.Exit(m.Run()) +} |