aboutsummaryrefslogtreecommitdiff
path: root/tests/gistatic.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/gistatic.go102
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()
}