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 | |
parent | Makefile: Reorder CLI args to go(1) (diff) | |
download | papod-80cdec3927ea866aea27ec356ae1d3f525ae94d7.tar.gz papod-80cdec3927ea866aea27ec356ae1d3f525ae94d7.tar.xz |
Use "go tool" to build project
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 67 | ||||
-rw-r--r-- | src/main.go (renamed from src/cmd/main.go) | 2 | ||||
-rw-r--r-- | src/papod.go (renamed from src/lib.go) | 13 | ||||
-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 |
7 files changed, 159 insertions, 85 deletions
@@ -1,3 +1,6 @@ /*.bin +/src/*.a +/src/*.bin +/tests/*.a /tests/*.bin /papod.db @@ -8,6 +8,7 @@ LANGUAGES = en PREFIX = /usr BINDIR = $(PREFIX)/bin LIBDIR = $(PREFIX)/lib +GOLIBDIR = $(LIBDIR)/go INCLUDEDIR = $(PREFIX)/include SRCDIR = $(PREFIX)/src/$(NAME) SHAREDIR = $(PREFIX)/share @@ -17,14 +18,12 @@ DATADIR = $(SHAREDIR)/$(NAME) EXEC = ./ ## Where to store the installation. Empty by default. DESTDIR = -LDLIBS = -GOFLAGS = -ldflags '-extldflags "-static -lm"' -tags 'linux libsqlite3 \ - json1 fts5 sqlite_foreign_keys sqlite_omit_load_extension' +LDLIBS = -lsqlite3 .SUFFIXES: -.SUFFIXES: .go .bin +.SUFFIXES: .go .a .bin .bin-check @@ -32,16 +31,24 @@ all: include deps.mk +objects = \ + src/$(NAME).a \ + src/main.a \ + tests/$(NAME).a \ + tests/main.a \ + sources = \ - src/lib.go \ - src/cmd/main.go \ + src/$(NAME).go \ + src/main.go \ $(sources.static) \ $(sources.sql) \ derived-assets = \ + $(objects) \ + src/main.bin \ + tests/main.bin \ $(NAME).bin \ - tests/lib_test.bin \ side-assets = \ papod.public.socket \ @@ -57,22 +64,44 @@ side-assets = \ all: $(derived-assets) -$(NAME).bin: src/lib.go src/cmd/main.go Makefile - env CGO_ENABLED=1 go build $(GOFLAGS) -v -o $@ src/cmd/main.go +$(objects): Makefile + +src/$(NAME).a: src/$(NAME).go +src/main.a: src/main.go src/$(NAME).a +tests/main.a: tests/main.go tests/$(NAME).a +src/$(NAME).a src/main.a tests/main.a: + go tool compile $(GOCFLAGS) -o $@ -p $(*F) -I $(@D) $*.go + +tests/$(NAME).a: tests/$(NAME).go src/$(NAME).go + go tool compile $(GOCFLAGS) -o $@ -p $(*F) $*.go src/$(*F).go + +src/main.bin: src/main.a +tests/main.bin: tests/main.a +src/main.bin tests/main.bin: + go tool link $(GOLDFLAGS) -o $@ -L $(@D) --extldflags '$(LDLIBS)' $*.a + +$(NAME).bin: src/main.bin + ln -fs $? $@ + -tests/lib_test.bin: src/lib.go tests/lib_test.go Makefile - env CGO_ENABLED=1 go test $(GOFLAGS) -v -o $@ -c $*.go +tests.bin-check = \ + tests/main.bin-check \ +tests/main.bin-check: tests/main.bin +$(tests.bin-check): + $(EXEC)$*.bin -check-unit: tests/lib_test.bin - ./tests/lib_test.bin +check-unit: $(tests.bin-check) integration-tests = \ tests/cli-opts.sh \ + tests/integration.sh \ -$(integration-tests): $(NAME).bin ALWAYS +.PRECIOUS: $(integration-tests) +$(integration-tests): $(NAME).bin +$(integration-tests): ALWAYS sh $@ check-integration: $(integration-tests) @@ -96,8 +125,11 @@ clean: install: all mkdir -p \ '$(DESTDIR)$(BINDIR)' \ + '$(DESTDIR)$(GOLIBDIR)' \ + '$(DESTDIR)$(SRCDIR)' \ cp $(NAME).bin '$(DESTDIR)$(BINDIR)'/$(NAME) + cp src/$(NAME).a '$(DESTDIR)$(GOLIBDIR)' for f in $(sources.sql) $(sources.static); do \ dir='$(DESTDIR)$(DATADIR)'/"`dirname "$${f#src/}"`"; \ mkdir -p "$$dir"; \ @@ -114,9 +146,10 @@ install: all ## A dedicated test asserts that this is always true. uninstall: rm -rf \ - '$(DESTDIR)$(BINDIR)'/$(NAME) \ - '$(DESTDIR)$(DATADIR)' \ - '$(DESTDIR)$(SRCDIR)' \ + '$(DESTDIR)$(BINDIR)'/$(NAME) \ + '$(DESTDIR)$(GOLIBDIR)'/$(NAME).a \ + '$(DESTDIR)$(DATADIR)' \ + '$(DESTDIR)$(SRCDIR)' \ run-papod: $(NAME).bin diff --git a/src/cmd/main.go b/src/main.go index 8e80599..b591f5c 100644 --- a/src/cmd/main.go +++ b/src/main.go @@ -1,6 +1,6 @@ package main -import "euandre.org/papod/src" +import "papod" func main() { papod.Main() diff --git a/src/lib.go b/src/papod.go index b06829a..91e1145 100644 --- a/src/lib.go +++ b/src/papod.go @@ -9,19 +9,16 @@ import ( "fmt" "io" "io/ioutil" - "log/slog" "net" "os" "regexp" - "runtime/debug" "sort" "strings" "sync" "time" - g "euandre.org/gobang/src" - - _ "github.com/mattn/go-sqlite3" + g "gobang" + _ "golite" ) @@ -206,7 +203,7 @@ func HandlePRIVMSG(ctx *Context, msg Message) { defer stmt.Close() ret, err := stmt.Exec( - g.NewUUID().ToString(), + g.NewUUID().String(), "FIXME", "FIXME", time.Now(), @@ -517,19 +514,23 @@ func Init() { } func Start(ctx *Context, publicSocketPath string, commandSocketPath string) { + /* buildInfo, ok := debug.ReadBuildInfo() if !ok { g.Fatal(errors.New("error on debug.ReadBuildInfo()")) } + */ g.Info("-", "lifecycle-event", "event", "starting-server", + /* slog.Group( "go", "version", buildInfo.GoVersion, "settings", buildInfo.Settings, "deps", buildInfo.Deps, ), + */ ) var wg sync.WaitGroup 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()) +} |