diff options
author | EuAndreh <eu@euandre.org> | 2025-05-11 07:58:03 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2025-05-11 07:58:03 -0300 |
commit | 04c91c40d548bb70062fcadeeeea37fd4319e066 (patch) | |
tree | e6c9c2d04de7544e5d3b0f2d48076c1da97a8975 /tests/gistatic.go | |
parent | src/gistatic.go: Add missing trailing newline to usage() output (diff) | |
download | gistatic-04c91c40d548bb70062fcadeeeea37fd4319e066.tar.gz gistatic-04c91c40d548bb70062fcadeeeea37fd4319e066.tar.xz |
Finish branches.html and setup i18n of manpages and HTML strings
Diffstat (limited to '')
-rw-r--r-- | tests/gistatic.go | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/tests/gistatic.go b/tests/gistatic.go index 9f09a22..5798a0c 100644 --- a/tests/gistatic.go +++ b/tests/gistatic.go @@ -1,4 +1,106 @@ package gistatic +import ( + "strings" + + g "gobang" +) + + + +func test_usage() { + g.TestStart("usage()") + + g.Testing("it writes the usage string to the io.Writer", func() { + w := strings.Builder{} + usage("xxx", &w) + + expected := g.Heredoc(` + Usage: xxx [-o DIRECTORY] [-u CLONE_URL] REPOSITORY... + `) + g.TAssertEqual(w.String(), expected) + }) +} + +func test_getopt() { + g.TestStart("getopt()") + + usage := g.Heredoc(` + Usage: $0 [-o DIRECTORY] [-u CLONE_URL] REPOSITORY... + `) + + g.Testing("we supress the default error message", func() { + w := strings.Builder{} + argv := []string{"$0", "-h"} + _, rc := getopt(argv, &w) + + g.TAssertEqual(w.String(), usage) + g.TAssertEqual(rc, 2) + }) + + g.Testing("we get unsupported flag error", func() { + w := strings.Builder{} + argv := []string{"$0", "-A"} + _, rc := getopt(argv, &w) + + const message = "flag provided but not defined: -A\n" + g.TAssertEqual(w.String(), message + usage) + g.TAssertEqual(rc, 2) + }) + + g.Testing("we get incorrect use of flag error", func() { + w1 := strings.Builder{} + argv1 := []string{"$0", "-u"} + _, rc1 := getopt(argv1, &w1) + + const message1 = "flag needs an argument: -u\n" + g.TAssertEqual(w1.String(), message1 + usage) + g.TAssertEqual(rc1, 2) + + w2 := strings.Builder{} + argv2 := []string{"$0", "-o"} + _, rc2 := getopt(argv2, &w2) + + const message2 = "flag needs an argument: -o\n" + g.TAssertEqual(w2.String(), message2 + usage) + g.TAssertEqual(rc2, 2) + }) + + g.Testing("the argsT has the flag URL value", func() { + fn_wdSaved := fn_wd + fn_wd = func() (string, error) { + return "virtual working directory", nil + } + + w := strings.Builder{} + argv := []string{"$0", "-u", "proto://URL", "a-path"} + expected := argsT{ + cloneURL: "proto://URL", + allArgs: []string{"$0", "-u", "proto://URL", "a-path"}, + subArgs: []string{"a-path"}, + outdir: "virtual working directory", + } + + args, rc := getopt(argv, &w) + + fn_wd = fn_wdSaved + + g.TAssertEqual(w.String(), "") + g.TAssertEqual(rc, 0) + g.TAssertEqual(args, expected) + }) +} + +func test_run() { + // FIXME +} + + + func MainTest() { + g.Init() + + test_usage() + test_getopt() + test_run() } |