summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/benchmarks/string-roundtrip/guuid.go37
l---------tests/benchmarks/string-roundtrip/main.go1
-rw-r--r--tests/functional/string-round-trip/guuid.go62
l---------tests/functional/string-round-trip/main.go1
-rw-r--r--tests/fuzz/from-string/guuid.go30
l---------tests/fuzz/from-string/main.go1
-rw-r--r--tests/fuzz/new-from/guuid.go31
l---------tests/fuzz/new-from/main.go1
-rw-r--r--tests/libbuild.go11
9 files changed, 164 insertions, 11 deletions
diff --git a/tests/benchmarks/string-roundtrip/guuid.go b/tests/benchmarks/string-roundtrip/guuid.go
new file mode 100644
index 0000000..9fef55c
--- /dev/null
+++ b/tests/benchmarks/string-roundtrip/guuid.go
@@ -0,0 +1,37 @@
+package guuid
+
+import (
+ "flag"
+ "fmt"
+)
+
+
+
+var nFlag = flag.Int(
+ "n",
+ 10_000_000,
+ "The number of iterations to execute",
+)
+
+func MainTest() {
+ flag.Parse()
+ n := *nFlag
+
+ uuid := New()
+
+ for i := 0; i < n; i++ {
+ derived, err := FromString(uuid.String())
+ if err != nil {
+ panic(err)
+ }
+
+ eq := uuid == derived
+ if !eq {
+ panic(fmt.Sprintf(
+ "bad round trip: orig (%#v); derived (%#v)",
+ uuid,
+ derived,
+ ))
+ }
+ }
+}
diff --git a/tests/benchmarks/string-roundtrip/main.go b/tests/benchmarks/string-roundtrip/main.go
new file mode 120000
index 0000000..f67563d
--- /dev/null
+++ b/tests/benchmarks/string-roundtrip/main.go
@@ -0,0 +1 @@
+../../main.go \ No newline at end of file
diff --git a/tests/functional/string-round-trip/guuid.go b/tests/functional/string-round-trip/guuid.go
new file mode 100644
index 0000000..764576e
--- /dev/null
+++ b/tests/functional/string-round-trip/guuid.go
@@ -0,0 +1,62 @@
+package guuid
+
+import (
+ "fmt"
+ "os"
+ "reflect"
+)
+
+
+
+func showColour() bool {
+ return os.Getenv("NO_COLOUR") == ""
+}
+
+func testing(message string, body func()) {
+ if showColour() {
+ fmt.Fprintf(
+ os.Stderr,
+ "\033[0;33mtesting\033[0m: %s... ",
+ message,
+ )
+ body()
+ fmt.Fprintf(os.Stderr, "\033[0;32mOK\033[0m.\n")
+ } else {
+ fmt.Fprintf(os.Stderr, "testing: %s... ", message)
+ body()
+ fmt.Fprintf(os.Stderr, "OK.\n")
+ }
+}
+
+func assertEq(given any, expected any) {
+ if !reflect.DeepEqual(given, expected) {
+ if showColour() {
+ fmt.Fprintf(os.Stderr, "\033[0;31mERR\033[0m.\n")
+ } else {
+ fmt.Fprintf(os.Stderr, "ERR.\n")
+ }
+ fmt.Fprintf(os.Stderr, "given != expected\n")
+ fmt.Fprintf(os.Stderr, "given: %#v\n", given)
+ fmt.Fprintf(os.Stderr, "expected: %#v\n", expected)
+ os.Exit(1)
+ }
+}
+
+
+
+func MainTest() {
+ testing("string is the same after round-trip", func() {
+ str1 := New().String()
+ id, err := FromString(str1)
+ assertEq(err, nil)
+ str2 := id.String()
+ assertEq(str1, str2)
+ })
+
+ testing("UUID is the same after round-trip", func() {
+ id1 := New()
+ id2, err := FromString(id1.String())
+ assertEq(err, nil)
+ assertEq(id1, id2)
+ })
+}
diff --git a/tests/functional/string-round-trip/main.go b/tests/functional/string-round-trip/main.go
new file mode 120000
index 0000000..f67563d
--- /dev/null
+++ b/tests/functional/string-round-trip/main.go
@@ -0,0 +1 @@
+../../main.go \ No newline at end of file
diff --git a/tests/fuzz/from-string/guuid.go b/tests/fuzz/from-string/guuid.go
new file mode 100644
index 0000000..8971cbb
--- /dev/null
+++ b/tests/fuzz/from-string/guuid.go
@@ -0,0 +1,30 @@
+package guuid
+
+import (
+ "os"
+ "testing"
+ "testing/internal/testdeps"
+)
+
+
+
+func fn(f *testing.F) {
+ f.Fuzz(func(t *testing.T, str string) {
+ FromString(str)
+ })
+}
+
+
+
+func MainTest() {
+ fuzzTargets := []testing.InternalFuzzTarget{
+ { "fn", fn },
+ }
+
+ deps := testdeps.TestDeps{}
+ tests := []testing.InternalTest {}
+ benchmarks := []testing.InternalBenchmark{}
+ examples := []testing.InternalExample {}
+ m := testing.MainStart(deps, tests, benchmarks, fuzzTargets, examples)
+ os.Exit(m.Run())
+}
diff --git a/tests/fuzz/from-string/main.go b/tests/fuzz/from-string/main.go
new file mode 120000
index 0000000..f67563d
--- /dev/null
+++ b/tests/fuzz/from-string/main.go
@@ -0,0 +1 @@
+../../main.go \ No newline at end of file
diff --git a/tests/fuzz/new-from/guuid.go b/tests/fuzz/new-from/guuid.go
new file mode 100644
index 0000000..a786c66
--- /dev/null
+++ b/tests/fuzz/new-from/guuid.go
@@ -0,0 +1,31 @@
+package guuid
+
+import (
+ "bytes"
+ "os"
+ "testing"
+ "testing/internal/testdeps"
+)
+
+
+
+func fn(f *testing.F) {
+ f.Fuzz(func(t *testing.T, payload []byte) {
+ NewFrom(bytes.NewReader(payload))
+ })
+}
+
+
+
+func MainTest() {
+ fuzzTargets := []testing.InternalFuzzTarget{
+ { "fn", fn },
+ }
+
+ deps := testdeps.TestDeps{}
+ tests := []testing.InternalTest {}
+ benchmarks := []testing.InternalBenchmark{}
+ examples := []testing.InternalExample {}
+ m := testing.MainStart(deps, tests, benchmarks, fuzzTargets, examples)
+ os.Exit(m.Run())
+}
diff --git a/tests/fuzz/new-from/main.go b/tests/fuzz/new-from/main.go
new file mode 120000
index 0000000..f67563d
--- /dev/null
+++ b/tests/fuzz/new-from/main.go
@@ -0,0 +1 @@
+../../main.go \ No newline at end of file
diff --git a/tests/libbuild.go b/tests/libbuild.go
deleted file mode 100644
index 2c02686..0000000
--- a/tests/libbuild.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package main
-
-import (
- "fmt"
-
- "guuid"
-)
-
-func main() {
- fmt.Println(guuid.New())
-}