From 2a6ae2c98bc0486751225a4c26323bfc26654a84 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Mon, 16 Dec 2013 14:24:40 -0700 Subject: [PATCH 01/39] Quick functions for generating TAP output --- util/tap/tap.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 util/tap/tap.go diff --git a/util/tap/tap.go b/util/tap/tap.go new file mode 100644 index 00000000..fd917d2e --- /dev/null +++ b/util/tap/tap.go @@ -0,0 +1,20 @@ +package tap + +import "fmt" + +// Header displays a TAP header including version number and expected +// number of tests to run. +func Header(testCount int) { + fmt.Printf("TAP version 13\n") + fmt.Printf("1..%d\n", testCount) +} + +// Ok generates TAP output indicating that a test has passed +func Ok(testNumber int, description string) { + fmt.Printf("ok %d - %s\n", testNumber, description) +} + +// NotOk generates TAP output indicating that a test has failed +func NotOk(testNumber int, description string) { + fmt.Printf("not ok %d - %s\n", testNumber, description) +} From 3336e7a949496efefec5b9c20abca8726b04e491 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Mon, 16 Dec 2013 14:48:40 -0700 Subject: [PATCH 02/39] Use test methods instead of functions Using methods allows us to track some state while running tests. This means we don't have to manually track test numbers. It also means we're structurally similar to Go's testing package so that we can emulate it. That should make it easier to port a test from testing to tap. --- util/tap/tap.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/util/tap/tap.go b/util/tap/tap.go index fd917d2e..3d8068d3 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -2,19 +2,30 @@ package tap import "fmt" +type T struct { + nextTestNumber int +} + +// New creates a new Tap value +func New() *T { + return &T{} +} + // Header displays a TAP header including version number and expected // number of tests to run. -func Header(testCount int) { +func (t *T) Header(testCount int) { fmt.Printf("TAP version 13\n") fmt.Printf("1..%d\n", testCount) } -// Ok generates TAP output indicating that a test has passed -func Ok(testNumber int, description string) { - fmt.Printf("ok %d - %s\n", testNumber, description) -} +// Ok generates TAP output indicating whether a test passed or failed. +func (t *T) Ok(test bool, description string) { + // did the test pass or not? + ok := "ok" + if !test { + ok = "not ok" + } -// NotOk generates TAP output indicating that a test has failed -func NotOk(testNumber int, description string) { - fmt.Printf("not ok %d - %s\n", testNumber, description) + fmt.Printf("%s %d - %s\n", ok, t.nextTestNumber, description) + t.nextTestNumber++ } From 2f21e10628ea95a5de1abe6fcf3a192e89d9c58e Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Mon, 16 Dec 2013 15:03:33 -0700 Subject: [PATCH 03/39] Start TAP tests at 1 They don't start at 0 which is the zero value for nextTestNumber --- util/tap/tap.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/tap/tap.go b/util/tap/tap.go index 3d8068d3..a1d6a3c5 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -8,7 +8,9 @@ type T struct { // New creates a new Tap value func New() *T { - return &T{} + return &T{ + nextTestNumber: 1, + } } // Header displays a TAP header including version number and expected From 00b01ab5722ae3dd9e675db229538997209fd0e2 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Mon, 16 Dec 2013 15:04:06 -0700 Subject: [PATCH 04/39] Test suite to make sure TAP is correct Run a small TAP test using prove to make sure the output is parsed correctly. --- util/tap/Makefile | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 util/tap/Makefile diff --git a/util/tap/Makefile b/util/tap/Makefile new file mode 100644 index 00000000..8804e236 --- /dev/null +++ b/util/tap/Makefile @@ -0,0 +1,5 @@ +.PHONY: test + +test: + go build main/test.go + prove -v -e '' ./test From b7c11a710bf0bdbe0402a281b51d807b0e54cfa4 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Tue, 17 Dec 2013 11:40:40 -0700 Subject: [PATCH 05/39] Support tests like "testing/quick" Perform the quick check and generate TAP output as appropriate. --- util/tap/tap.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/util/tap/tap.go b/util/tap/tap.go index a1d6a3c5..4ef9a102 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -1,6 +1,7 @@ package tap import "fmt" +import "testing/quick" type T struct { nextTestNumber int @@ -31,3 +32,16 @@ func (t *T) Ok(test bool, description string) { fmt.Printf("%s %d - %s\n", ok, t.nextTestNumber, description) t.nextTestNumber++ } + +// Check runs randomized tests against a function just as "testing/quick.Check" +// does. Success or failure generate appropriate TAP output. +func (t *T) Check(function interface {}, description string) { + err := quick.Check(function, nil) + if err == nil { + t.Ok(true, description) + return + } + + fmt.Printf("# %s\n", err) + t.Ok(false, description) +} From b02f6076feb2daf724e64574f2709d72a4875244 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Tue, 10 Mar 2015 13:37:23 -0600 Subject: [PATCH 06/39] Create LICENSE --- util/tap/LICENSE | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 util/tap/LICENSE diff --git a/util/tap/LICENSE b/util/tap/LICENSE new file mode 100644 index 00000000..cf1ab25d --- /dev/null +++ b/util/tap/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to From 9955d9813dc585b12ab62c81842a707f1a9e4a60 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Tue, 10 May 2016 07:57:39 -0600 Subject: [PATCH 07/39] go fmt --- util/tap/tap.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/util/tap/tap.go b/util/tap/tap.go index 4ef9a102..deb18682 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -35,13 +35,13 @@ func (t *T) Ok(test bool, description string) { // Check runs randomized tests against a function just as "testing/quick.Check" // does. Success or failure generate appropriate TAP output. -func (t *T) Check(function interface {}, description string) { - err := quick.Check(function, nil) - if err == nil { - t.Ok(true, description) - return - } - - fmt.Printf("# %s\n", err) - t.Ok(false, description) +func (t *T) Check(function interface{}, description string) { + err := quick.Check(function, nil) + if err == nil { + t.Ok(true, description) + return + } + + fmt.Printf("# %s\n", err) + t.Ok(false, description) } From e567098c38cb0d2f7e3d7f1f4ddac9ac7825d91d Mon Sep 17 00:00:00 2001 From: Tommie McAfee Date: Mon, 9 May 2016 13:58:30 -0400 Subject: [PATCH 08/39] Count method returning number of tests --- util/tap/tap.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/tap/tap.go b/util/tap/tap.go index deb18682..0d8fbbb4 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -45,3 +45,8 @@ func (t *T) Check(function interface{}, description string) { fmt.Printf("# %s\n", err) t.Ok(false, description) } + +// Count returns the number of tests completed so far. +func (t *T) Count() int { + return t.nextTestNumber - 1 +} From d8624b427df74088f6c290ef3025720ffeb6e48f Mon Sep 17 00:00:00 2001 From: Tommie McAfee Date: Mon, 9 May 2016 14:05:17 -0400 Subject: [PATCH 09/39] Add AutoPlan method --- util/tap/tap.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/tap/tap.go b/util/tap/tap.go index 0d8fbbb4..40a0472d 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -50,3 +50,8 @@ func (t *T) Check(function interface{}, description string) { func (t *T) Count() int { return t.nextTestNumber - 1 } + +// AutoPlan generates a test plan based on the number of tests that were run. +func (t *T) AutoPlan() { + fmt.Printf("1..%d\n", t.nextTestNumber-1) +} From 2d3e5598aaae1ad51f6341fe05a44fc52064072b Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 28 Sep 2016 10:01:28 -0700 Subject: [PATCH 10/39] tap: Teach Header to skip the plan when testCount < 1 More on this use case in [1]. [1]: http://testanything.org/tap-version-13-specification.html#unknown-amount-and-failures --- util/tap/tap.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/util/tap/tap.go b/util/tap/tap.go index 40a0472d..7366ce84 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -15,10 +15,14 @@ func New() *T { } // Header displays a TAP header including version number and expected -// number of tests to run. +// number of tests to run. For an unknown number of tests, set +// testCount to zero (in which case the plan is not written); this is +// useful with AutoPlan. func (t *T) Header(testCount int) { fmt.Printf("TAP version 13\n") - fmt.Printf("1..%d\n", testCount) + if testCount > 0 { + fmt.Printf("1..%d\n", testCount) + } } // Ok generates TAP output indicating whether a test passed or failed. From f0db097a2355fc0bacd86b1a6ccedaa97c7f2bb1 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 28 Sep 2016 10:12:23 -0700 Subject: [PATCH 11/39] Add tests for AutoPlan And adjust the Makefile to make it easy to build future test/*/main.go using a static pattern rule [1]. The TESTS entries are phony to force rebuilds every time, because 'go build' includes logic to avoid unnecessary rebuilds. [1]: https://www.gnu.org/software/make/manual/html_node/Static-Usage.html --- util/tap/Makefile | 12 ++++++++---- util/tap/test/auto/main.go | 11 +++++++++++ util/tap/test/known/main.go | 10 ++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 util/tap/test/auto/main.go create mode 100644 util/tap/test/known/main.go diff --git a/util/tap/Makefile b/util/tap/Makefile index 8804e236..8632731d 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -1,5 +1,9 @@ -.PHONY: test +TESTS = known auto -test: - go build main/test.go - prove -v -e '' ./test +.PHONY: $(TESTS) + +all: $(TESTS) + +$(TESTS): %: test/%/main.go + go build -o $@ test/$@/main.go + prove -v -e '' ./$@ diff --git a/util/tap/test/auto/main.go b/util/tap/test/auto/main.go new file mode 100644 index 00000000..ac5367c1 --- /dev/null +++ b/util/tap/test/auto/main.go @@ -0,0 +1,11 @@ +package main + +import "github.com/mndrix/tap.go" + +func main() { + t := tap.New() + t.Header(0) + t.Ok(true, "first test") + t.Ok(true, "second test") + t.AutoPlan() +} diff --git a/util/tap/test/known/main.go b/util/tap/test/known/main.go new file mode 100644 index 00000000..b58db3fb --- /dev/null +++ b/util/tap/test/known/main.go @@ -0,0 +1,10 @@ +package main + +import "github.com/mndrix/tap.go" + +func main() { + t := tap.New() + t.Header(2) + t.Ok(true, "first test") + t.Ok(true, "second test") +} From ed0683e0e47d846364a9cc46a5f8b73cd2f3aecd Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Wed, 28 Sep 2016 14:46:45 -0400 Subject: [PATCH 12/39] Rename repository It's very difficult to use "go get" to fetch a repository that ends with .go To avoid this problem, rename this repository to end with -go Update the canonical import path accordingly. --- util/tap/tap.go | 2 +- util/tap/test/auto/main.go | 2 +- util/tap/test/known/main.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/util/tap/tap.go b/util/tap/tap.go index 7366ce84..a3fd1c83 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -1,4 +1,4 @@ -package tap +package tap // import "github.com/mndrix/tap-go" import "fmt" import "testing/quick" diff --git a/util/tap/test/auto/main.go b/util/tap/test/auto/main.go index ac5367c1..24dc4809 100644 --- a/util/tap/test/auto/main.go +++ b/util/tap/test/auto/main.go @@ -1,6 +1,6 @@ package main -import "github.com/mndrix/tap.go" +import "github.com/mndrix/tap-go" func main() { t := tap.New() diff --git a/util/tap/test/known/main.go b/util/tap/test/known/main.go index b58db3fb..677963ac 100644 --- a/util/tap/test/known/main.go +++ b/util/tap/test/known/main.go @@ -1,6 +1,6 @@ package main -import "github.com/mndrix/tap.go" +import "github.com/mndrix/tap-go" func main() { t := tap.New() From 9bdb5f127b3e565df015f24b1c2c8ad6f90d1e0d Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Wed, 28 Sep 2016 15:11:05 -0400 Subject: [PATCH 13/39] Keep test binaries inside the test/ directory This commit makes all test binaries follow the naming pattern test/foo/test This allows us to reference all test binaries with a single glob pattern: test/*/test The utility of this arrangements is already evident in .gitignore which now needs only a single line and automatically ignores all future test binaries. --- util/tap/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/tap/Makefile b/util/tap/Makefile index 8632731d..3bc7c5ee 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -5,5 +5,5 @@ TESTS = known auto all: $(TESTS) $(TESTS): %: test/%/main.go - go build -o $@ test/$@/main.go - prove -v -e '' ./$@ + go build -o test/$@/test test/$@/main.go + prove -v -e '' test/$@/test From c3d12843c75e0844155e65fccea6dc011f15460a Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Wed, 28 Sep 2016 15:14:30 -0400 Subject: [PATCH 14/39] Add a 'clean' rule to remove all test binaries --- util/tap/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util/tap/Makefile b/util/tap/Makefile index 3bc7c5ee..dffb470d 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -4,6 +4,9 @@ TESTS = known auto all: $(TESTS) +clean: + rm -f test/*/test + $(TESTS): %: test/%/main.go go build -o test/$@/test test/$@/main.go prove -v -e '' test/$@/test From 368f25b67381b176299edf43d191204701bbc6e5 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Wed, 28 Sep 2016 15:16:09 -0400 Subject: [PATCH 15/39] Run all tests with a single harness Instead of running several separate prove commands (one per test), we now run a single prove command which executes all tests itself. This gives us a single test summary after all tests have concluded which should scale better as we add more tests. --- util/tap/Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/util/tap/Makefile b/util/tap/Makefile index dffb470d..157e867c 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -2,11 +2,14 @@ TESTS = known auto .PHONY: $(TESTS) -all: $(TESTS) +all: test/*/test + prove -v -e '' test/*/test clean: rm -f test/*/test -$(TESTS): %: test/%/main.go - go build -o test/$@/test test/$@/main.go +test/%/test: test/%/main.go + go build -o $@ $< + +$(TESTS): %: test/%/test prove -v -e '' test/$@/test From 3e8d9574f42c122c43f831ef71b24f972c52149e Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Wed, 28 Sep 2016 15:27:00 -0400 Subject: [PATCH 16/39] Add tests for Check() --- util/tap/Makefile | 2 +- util/tap/test/check/main.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 util/tap/test/check/main.go diff --git a/util/tap/Makefile b/util/tap/Makefile index 157e867c..1193ca77 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -1,4 +1,4 @@ -TESTS = known auto +TESTS = auto check known .PHONY: $(TESTS) diff --git a/util/tap/test/check/main.go b/util/tap/test/check/main.go new file mode 100644 index 00000000..d780e0d5 --- /dev/null +++ b/util/tap/test/check/main.go @@ -0,0 +1,16 @@ +package main + +import "github.com/mndrix/tap-go" + +func main() { + add := func(x int) bool { return x+3 > x } + sub := func(x int) bool { return x-3 < x } + one := func(x int) bool { return x*1 == x } + + t := tap.New() + t.Header(0) + t.Check(add, "addition makes numbers larger") + t.Check(sub, "subtraction makes numbers smaller") + t.Check(one, "1 is a multiplicative identity") + t.AutoPlan() +} From e5fc669a12a77a398c503da896b38367b64def23 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Thu, 1 Dec 2016 10:06:11 -0500 Subject: [PATCH 17/39] Add basic README --- util/tap/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 util/tap/README.md diff --git a/util/tap/README.md b/util/tap/README.md new file mode 100644 index 00000000..f795022d --- /dev/null +++ b/util/tap/README.md @@ -0,0 +1,7 @@ +# Test Anything Protocol for Go + +The [Test Anything Protocol](http://testanything.org/) ("TAP") is a text-based +interface between tests and a test harness. This package helps Go to generate +TAP output. + +Read the [full package documentation](https://godoc.org/github.com/mndrix/tap-go) From 2bc21a4675730dc695a1b06fed872f6021575bc9 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Thu, 1 Dec 2016 10:06:24 -0500 Subject: [PATCH 18/39] Use Count() inside AutoPlan() --- util/tap/tap.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/tap/tap.go b/util/tap/tap.go index a3fd1c83..9a2c0f7f 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -57,5 +57,5 @@ func (t *T) Count() int { // AutoPlan generates a test plan based on the number of tests that were run. func (t *T) AutoPlan() { - fmt.Printf("1..%d\n", t.nextTestNumber-1) + fmt.Printf("1..%d\n", t.Count()) } From c07a1b71ad735ca4afd35c337cbfc1aa4af3a305 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Thu, 1 Dec 2016 10:07:16 -0500 Subject: [PATCH 19/39] More documentation --- util/tap/tap.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/util/tap/tap.go b/util/tap/tap.go index 9a2c0f7f..ec10655e 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -1,8 +1,30 @@ +// Package tap provides support for automated Test Anything Protocol ("TAP") +// tests in Go. For example: +// +// package main +// +// import "github.com/mndrix/tap-go" +// +// func main() { +// t := tap.New() +// t.Header(2) +// t.Ok(true, "first test") +// t.Ok(true, "second test") +// } +// +// generates the following output +// +// TAP version 13 +// 1..2 +// ok 1 - first test +// ok 2 - second test package tap // import "github.com/mndrix/tap-go" import "fmt" import "testing/quick" +// T is a type to encapsulate test state. Methods on this type generate TAP +// output. type T struct { nextTestNumber int } From 2ab24281e0e9ea4a852d41566f004899be23fbc4 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Thu, 1 Dec 2016 10:58:28 -0500 Subject: [PATCH 20/39] GOPATH symlink hack The test programs in test/*/main.go all import "github.com/mndrix/tap-go". By default Go will look in the user's GOPATH to find that package. That means a user working on tap-go itself has to install the untested, development version of the package into his GOPATH before he can run the test suite. That's inconvenient and likely to break other code which relies on a working version of tap-go. The hack in this commit creates a private GOPATH within our repository which only includes the package under development. Running the test suite always uses the latest code in the repository and doesn't require our developers to manually adjust their own GOPATH each time. --- util/tap/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/util/tap/Makefile b/util/tap/Makefile index 1193ca77..6d669aaa 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -1,4 +1,5 @@ TESTS = auto check known +GOPATH = $(CURDIR)/gopath .PHONY: $(TESTS) From 4f77f9f80511232e89b7600142a57d0c68864e9d Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Thu, 1 Dec 2016 11:04:33 -0500 Subject: [PATCH 21/39] Rebuild test scripts if tap.go changes --- util/tap/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/tap/Makefile b/util/tap/Makefile index 6d669aaa..09676ab7 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -9,7 +9,7 @@ all: test/*/test clean: rm -f test/*/test -test/%/test: test/%/main.go +test/%/test: test/%/main.go tap.go go build -o $@ $< $(TESTS): %: test/%/test From 34b25bdc37cff4521be3149f21737a1139c555f9 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Thu, 1 Dec 2016 11:34:03 -0500 Subject: [PATCH 22/39] Fix Makefile dependencies for "all" The old pattern said "this rule depends on whatever files exist and match this glob". The new pattern says "this rules depends on test/auto/test and test/check/test and ... regardless of whether they exist yet". Without this change "make all" only ran tests which had already been compiled. --- util/tap/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/tap/Makefile b/util/tap/Makefile index 09676ab7..f9baf573 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -3,7 +3,7 @@ GOPATH = $(CURDIR)/gopath .PHONY: $(TESTS) -all: test/*/test +all: $(foreach t,$(TESTS),test/$(t)/test) prove -v -e '' test/*/test clean: From 8615712b92168cf7d25b1d2f9461b5a7c95185fa Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Thu, 1 Dec 2016 10:16:32 -0500 Subject: [PATCH 23/39] Use our own printf method for output This is a step towards sending TAP output to an arbitrary io.Writer --- util/tap/tap.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/util/tap/tap.go b/util/tap/tap.go index ec10655e..12d61663 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -20,7 +20,10 @@ // ok 2 - second test package tap // import "github.com/mndrix/tap-go" -import "fmt" +import ( + "fmt" + "os" +) import "testing/quick" // T is a type to encapsulate test state. Methods on this type generate TAP @@ -36,14 +39,18 @@ func New() *T { } } +func (t *T) printf(format string, a ...interface{}) { + fmt.Printf(format, a...) +} + // Header displays a TAP header including version number and expected // number of tests to run. For an unknown number of tests, set // testCount to zero (in which case the plan is not written); this is // useful with AutoPlan. func (t *T) Header(testCount int) { - fmt.Printf("TAP version 13\n") + t.printf("TAP version 13\n") if testCount > 0 { - fmt.Printf("1..%d\n", testCount) + t.printf("1..%d\n", testCount) } } @@ -55,7 +62,7 @@ func (t *T) Ok(test bool, description string) { ok = "not ok" } - fmt.Printf("%s %d - %s\n", ok, t.nextTestNumber, description) + t.printf("%s %d - %s\n", ok, t.nextTestNumber, description) t.nextTestNumber++ } @@ -68,7 +75,7 @@ func (t *T) Check(function interface{}, description string) { return } - fmt.Printf("# %s\n", err) + t.printf("# %s\n", err) t.Ok(false, description) } @@ -79,5 +86,5 @@ func (t *T) Count() int { // AutoPlan generates a test plan based on the number of tests that were run. func (t *T) AutoPlan() { - fmt.Printf("1..%d\n", t.Count()) + t.printf("1..%d\n", t.Count()) } From c4add1abd68177a08f6cf7d90f971905e2abd0f0 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Thu, 1 Dec 2016 11:08:06 -0500 Subject: [PATCH 24/39] Send TAP output to any io.Writer In some contexts a TAP test can't send output directly to stdout. Instead it should be sent to some other writer (HTTP stream, buffer, etc). Allow this usage without breaking existing users. --- util/tap/Makefile | 2 +- util/tap/tap.go | 13 ++++++++++++- util/tap/test/writer/main.go | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 util/tap/test/writer/main.go diff --git a/util/tap/Makefile b/util/tap/Makefile index f9baf573..6c743279 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -1,4 +1,4 @@ -TESTS = auto check known +TESTS = auto check known writer GOPATH = $(CURDIR)/gopath .PHONY: $(TESTS) diff --git a/util/tap/tap.go b/util/tap/tap.go index 12d61663..9daea96f 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -22,6 +22,7 @@ package tap // import "github.com/mndrix/tap-go" import ( "fmt" + "io" "os" ) import "testing/quick" @@ -30,6 +31,9 @@ import "testing/quick" // output. type T struct { nextTestNumber int + + // Writer indicates where TAP output should be sent. The default is os.Stdout. + Writer io.Writer } // New creates a new Tap value @@ -39,8 +43,15 @@ func New() *T { } } +func (t *T) w() io.Writer { + if t.Writer == nil { + return os.Stdout + } + return t.Writer +} + func (t *T) printf(format string, a ...interface{}) { - fmt.Printf(format, a...) + fmt.Fprintf(t.w(), format, a...) } // Header displays a TAP header including version number and expected diff --git a/util/tap/test/writer/main.go b/util/tap/test/writer/main.go new file mode 100644 index 00000000..11f826df --- /dev/null +++ b/util/tap/test/writer/main.go @@ -0,0 +1,19 @@ +package main + +import ( + "bytes" + "os" + + "github.com/mndrix/tap-go" +) + +func main() { + buf := new(bytes.Buffer) + t := tap.New() + t.Writer = buf + t.Header(2) + t.Ok(true, "a test") + t.Ok(buf.Len() > 0, "buffer has content") + + buf.WriteTo(os.Stdout) +} From a39a5d7fa13f04898dbe5e85ef66eabfd081256e Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Thu, 1 Dec 2016 11:57:04 -0500 Subject: [PATCH 25/39] Cover failing tests The previous test suite only included passing tests. We want to cover failing tests too. --- util/tap/Makefile | 2 +- util/tap/test/failing/main.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 util/tap/test/failing/main.go diff --git a/util/tap/Makefile b/util/tap/Makefile index 6c743279..a8a937c6 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -1,4 +1,4 @@ -TESTS = auto check known writer +TESTS = auto check known failing writer GOPATH = $(CURDIR)/gopath .PHONY: $(TESTS) diff --git a/util/tap/test/failing/main.go b/util/tap/test/failing/main.go new file mode 100644 index 00000000..bf0a040f --- /dev/null +++ b/util/tap/test/failing/main.go @@ -0,0 +1,9 @@ +package main + +import "github.com/mndrix/tap-go" + +func main() { + t := tap.New() + t.Header(1) + t.Ok(false, "first test") +} From 010390e2f7e469844bc3d451f75b18e41521964f Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Thu, 1 Dec 2016 11:58:53 -0500 Subject: [PATCH 26/39] Add Pass() and Fail() These are sometimes helpful in complex tests. --- util/tap/tap.go | 12 ++++++++++++ util/tap/test/failing/main.go | 3 ++- util/tap/test/known/main.go | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/util/tap/tap.go b/util/tap/tap.go index 9daea96f..b889d196 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -77,6 +77,18 @@ func (t *T) Ok(test bool, description string) { t.nextTestNumber++ } +// Fail indicates that a test has failed. This is typically only used when the +// logic is too complex to fit naturally into an Ok() call. +func (t *T) Fail(description string) { + t.Ok(false, description) +} + +// Pass indicates that a test has passed. This is typically only used when the +// logic is too complex to fit naturally into an Ok() call. +func (t *T) Pass(description string) { + t.Ok(true, description) +} + // Check runs randomized tests against a function just as "testing/quick.Check" // does. Success or failure generate appropriate TAP output. func (t *T) Check(function interface{}, description string) { diff --git a/util/tap/test/failing/main.go b/util/tap/test/failing/main.go index bf0a040f..32922631 100644 --- a/util/tap/test/failing/main.go +++ b/util/tap/test/failing/main.go @@ -4,6 +4,7 @@ import "github.com/mndrix/tap-go" func main() { t := tap.New() - t.Header(1) + t.Header(2) t.Ok(false, "first test") + t.Fail("second test") } diff --git a/util/tap/test/known/main.go b/util/tap/test/known/main.go index 677963ac..5714f799 100644 --- a/util/tap/test/known/main.go +++ b/util/tap/test/known/main.go @@ -6,5 +6,5 @@ func main() { t := tap.New() t.Header(2) t.Ok(true, "first test") - t.Ok(true, "second test") + t.Pass("second test") } From 0fa2830ce2f970e5312c55fca19c2294ae3eec49 Mon Sep 17 00:00:00 2001 From: Simon Guest Date: Thu, 5 Jan 2017 13:52:35 +1300 Subject: [PATCH 27/39] Added Diagnostic and Diagnosticf. These produce diagnostic output, as defined by the TAP spec. --- util/tap/tap.go | 10 ++++++++++ util/tap/test/diagnostic/main.go | 11 +++++++++++ 2 files changed, 21 insertions(+) create mode 100644 util/tap/test/diagnostic/main.go diff --git a/util/tap/tap.go b/util/tap/tap.go index b889d196..643fad8f 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -111,3 +111,13 @@ func (t *T) Count() int { func (t *T) AutoPlan() { t.printf("1..%d\n", t.Count()) } + +// Diagnostic generates a diagnostic from the message. +func (t *T) Diagnostic(message string) { + t.printf("# %s\n", message) +} + +// Diagnosticf generates a diagnostic from the format string and arguments. +func (t *T) Diagnosticf(format string, a ...interface{}) { + t.printf("# "+format+"\n", a...) +} diff --git a/util/tap/test/diagnostic/main.go b/util/tap/test/diagnostic/main.go new file mode 100644 index 00000000..da1a7e28 --- /dev/null +++ b/util/tap/test/diagnostic/main.go @@ -0,0 +1,11 @@ +package main + +import "github.com/mndrix/tap-go" + +func main() { + t := tap.New() + t.Header(1) + t.Diagnostic("expecting all to be well") + t.Diagnosticf("here's some perfectly magical output: %d %s 0x%X.", 6, "abracadabra", 28) + t.Pass("all good") +} From 1c3ba86b3803368d12c24f8142e5f9a58099e6c4 Mon Sep 17 00:00:00 2001 From: Simon Guest Date: Thu, 5 Jan 2017 14:29:54 +1300 Subject: [PATCH 28/39] Allow for embedded newlines in diagnostics. --- util/tap/tap.go | 15 +++++++++++---- util/tap/test/diagnostic/main.go | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/util/tap/tap.go b/util/tap/tap.go index 643fad8f..e55cbbf1 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -24,6 +24,7 @@ import ( "fmt" "io" "os" + "strings" ) import "testing/quick" @@ -112,12 +113,18 @@ func (t *T) AutoPlan() { t.printf("1..%d\n", t.Count()) } -// Diagnostic generates a diagnostic from the message. +func escapeNewlines(s string) string { + return strings.Replace(strings.TrimRight(s, "\n"), "\n", "\n# ", -1) +} + +// Diagnostic generates a diagnostic from the message, +// which may span multiple lines. func (t *T) Diagnostic(message string) { - t.printf("# %s\n", message) + t.printf("# %s\n", escapeNewlines(message)) } -// Diagnosticf generates a diagnostic from the format string and arguments. +// Diagnosticf generates a diagnostic from the format string and arguments, +// which may span multiple lines. func (t *T) Diagnosticf(format string, a ...interface{}) { - t.printf("# "+format+"\n", a...) + t.printf("# "+escapeNewlines(format)+"\n", a...) } diff --git a/util/tap/test/diagnostic/main.go b/util/tap/test/diagnostic/main.go index da1a7e28..efb2a285 100644 --- a/util/tap/test/diagnostic/main.go +++ b/util/tap/test/diagnostic/main.go @@ -7,5 +7,7 @@ func main() { t.Header(1) t.Diagnostic("expecting all to be well") t.Diagnosticf("here's some perfectly magical output: %d %s 0x%X.", 6, "abracadabra", 28) + t.Diagnostic("some\nmultiline\ntext\n") + t.Diagnosticf("%d lines\n%s multiline\ntext", 3, "more") t.Pass("all good") } From 3d4b01e670e93d190c2fb8d3381e4e5fd25b6f4d Mon Sep 17 00:00:00 2001 From: Simon Guest Date: Fri, 6 Jan 2017 09:14:13 +1300 Subject: [PATCH 29/39] Added diagnostic test to Makefile. --- util/tap/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/tap/Makefile b/util/tap/Makefile index a8a937c6..dda78b2b 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -1,4 +1,4 @@ -TESTS = auto check known failing writer +TESTS = auto check diagnostic known failing writer GOPATH = $(CURDIR)/gopath .PHONY: $(TESTS) From 80022f604d2bcda510534b4b42506c1b679ae654 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 5 Jan 2017 13:55:35 -0800 Subject: [PATCH 30/39] test/failing: Wrap failing tests in another harness Use two harnesses, where the inner harness has failing tests and writes to a buffer. The outer harness checks that buffer to ensure the output is appropriate. This lets the whole test suite pass: $ make ... All tests successful. Files=6, Tests=15, 0 wallclock secs ( 0.05 usr 0.01 sys + 0.00 cusr 0.01 csys = 0.07 CPU) Result: PASS while before this commit it failed: $ make ... Test Summary Report ------------------- test/failing/test (Wstat: 0 Tests: 2 Failed: 2) Failed tests: 1-2 Files=6, Tests=15, 0 wallclock secs ( 0.05 usr + 0.00 sys = 0.05 CPU) Result: FAIL Makefile:7: recipe for target 'all' failed make: *** [all] Error 1 --- util/tap/test/failing/main.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/util/tap/test/failing/main.go b/util/tap/test/failing/main.go index 32922631..5b768662 100644 --- a/util/tap/test/failing/main.go +++ b/util/tap/test/failing/main.go @@ -1,10 +1,25 @@ package main -import "github.com/mndrix/tap-go" +import ( + "bytes" + + "github.com/mndrix/tap-go" +) func main() { - t := tap.New() - t.Header(2) - t.Ok(false, "first test") - t.Fail("second test") + t1 := tap.New() + t1.Header(2) + + buf := new(bytes.Buffer) + t2 := tap.New() + t2.Writer = buf + t2.Header(2) + + buf.Reset() + t2.Ok(false, "first test") + t1.Ok(buf.String() == "not ok 1 - first test\n", "Ok(false, ...) produces appropriate output") + + buf.Reset() + t2.Fail("second test") + t1.Ok(buf.String() == "not ok 2 - second test\n", "Fail(...) produces appropriate output") } From 76112da7fc92b8c819943cf57e8e06319e5050aa Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Thu, 5 Jan 2017 18:20:57 -0500 Subject: [PATCH 31/39] Explicitly test diagnostic output To verify the changes in #4, I intentionally broke Diagnostic() by prefixing lines with "!" instead of "#" but the tests still passed. The spec[1] allows a test harness to silently ignore lines it doesn't understand, so that behavior makes sense. Red light green light testing[2] requires that our test be capable of failing if something is broken. This commit adds that by comparing the actual output against our expected output. Hat tip to @wking for suggesting to compare output[3]. 1: http://testanything.org/tap-version-13-specification.html#anything-else 2: http://stackoverflow.com/a/404860/174463 3: https://github.com/mndrix/tap-go/pull/4#issuecomment-270767815 --- util/tap/test/diagnostic/main.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/util/tap/test/diagnostic/main.go b/util/tap/test/diagnostic/main.go index efb2a285..6d3b458f 100644 --- a/util/tap/test/diagnostic/main.go +++ b/util/tap/test/diagnostic/main.go @@ -1,13 +1,37 @@ package main -import "github.com/mndrix/tap-go" +import ( + "bytes" + "io" + "os" + + tap "github.com/mndrix/tap-go" +) func main() { + // collect output for comparison later + buf := new(bytes.Buffer) t := tap.New() + t.Writer = io.MultiWriter(os.Stdout, buf) + t.Header(1) t.Diagnostic("expecting all to be well") t.Diagnosticf("here's some perfectly magical output: %d %s 0x%X.", 6, "abracadabra", 28) t.Diagnostic("some\nmultiline\ntext\n") t.Diagnosticf("%d lines\n%s multiline\ntext", 3, "more") - t.Pass("all good") + + got := buf.String() + t.Ok(got == expected, "diagnostics gave expected output") } + +const expected = `TAP version 13 +1..1 +# expecting all to be well +# here's some perfectly magical output: 6 abracadabra 0x1C. +# some +# multiline +# text +# 3 lines +# more multiline +# text +` From 19f6898bc395ba3c16c6dde2244644895a673a2b Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Thu, 5 Jan 2017 18:45:22 -0500 Subject: [PATCH 32/39] Use Diagnostic() inside Check() Now that we have a function to generate diagnostic output, we don't have to construct it manually. See #4 --- util/tap/tap.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/tap/tap.go b/util/tap/tap.go index e55cbbf1..ed80670e 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -99,7 +99,7 @@ func (t *T) Check(function interface{}, description string) { return } - t.printf("# %s\n", err) + t.Diagnostic(err.Error()) t.Ok(false, description) } From 2dfd6650727e8e3b8c4bd079fe7bb7ffe7396ed7 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Thu, 5 Jan 2017 18:48:54 -0500 Subject: [PATCH 33/39] go fmt --- util/tap/tap.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/util/tap/tap.go b/util/tap/tap.go index ed80670e..43a4dd74 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -1,23 +1,23 @@ // Package tap provides support for automated Test Anything Protocol ("TAP") // tests in Go. For example: // -// package main +// package main // -// import "github.com/mndrix/tap-go" +// import "github.com/mndrix/tap-go" // -// func main() { -// t := tap.New() -// t.Header(2) -// t.Ok(true, "first test") -// t.Ok(true, "second test") -// } +// func main() { +// t := tap.New() +// t.Header(2) +// t.Ok(true, "first test") +// t.Ok(true, "second test") +// } // // generates the following output // -// TAP version 13 -// 1..2 -// ok 1 - first test -// ok 2 - second test +// TAP version 13 +// 1..2 +// ok 1 - first test +// ok 2 - second test package tap // import "github.com/mndrix/tap-go" import ( From 81d3a42157f94a68a381dc022a0d014aa7541794 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 11 Jan 2017 13:53:47 -0800 Subject: [PATCH 34/39] Add T.Skip(count int, description string) The spec [1] suggests "ok 23 # SKIP ...", but if you attempt this with: t.Pass("# SKIP foo") you get an extra hyphen ("ok 23 - # SKIP foo") which is parsed as a successful test (and not a skipped test). Michael gives the following example to motivate 'count' [2]: if ConditionIsMet() { t.Ok(Foo(), "foo") t.Ok(Bar(), "bar") } else { t.Skip(2, "condition not met") } The spec example of this is in [3], showing no special syntax for skipping multiple tests (although there is a special syntax for skipping *all* the tests). Also alphabetize TESTS in the Makefile. [1]: http://testanything.org/tap-version-13-specification.html#skipping-tests [2]: https://github.com/mndrix/tap-go/pull/6#issuecomment-272041306 [3]: http://testanything.org/tap-version-13-specification.html#skipping-a-few --- util/tap/Makefile | 2 +- util/tap/tap.go | 8 ++++++++ util/tap/test/skip/main.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 util/tap/test/skip/main.go diff --git a/util/tap/Makefile b/util/tap/Makefile index dda78b2b..b06163f9 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -1,4 +1,4 @@ -TESTS = auto check diagnostic known failing writer +TESTS = auto check diagnostic failing known skip writer GOPATH = $(CURDIR)/gopath .PHONY: $(TESTS) diff --git a/util/tap/tap.go b/util/tap/tap.go index 43a4dd74..fdc827d2 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -117,6 +117,14 @@ func escapeNewlines(s string) string { return strings.Replace(strings.TrimRight(s, "\n"), "\n", "\n# ", -1) } +// Skip indicates that a test has been skipped. +func (t *T) Skip(count int, description string) { + for i := 0; i < count; i++ { + t.printf("ok %d # SKIP %s\n", t.nextTestNumber, description) + t.nextTestNumber++ + } +} + // Diagnostic generates a diagnostic from the message, // which may span multiple lines. func (t *T) Diagnostic(message string) { diff --git a/util/tap/test/skip/main.go b/util/tap/test/skip/main.go new file mode 100644 index 00000000..5bc2161c --- /dev/null +++ b/util/tap/test/skip/main.go @@ -0,0 +1,30 @@ +package main + +import ( + "bytes" + "io" + "os" + + tap "github.com/mndrix/tap-go" +) + +func main() { + // collect output for comparison later + buf := new(bytes.Buffer) + t := tap.New() + t.Writer = io.MultiWriter(os.Stdout, buf) + + t.Header(4) + t.Skip(1, "insufficient flogiston pressure") + t.Skip(2, "no /sys directory") + + got := buf.String() + t.Ok(got == expected, "skip gave expected output") +} + +const expected = `TAP version 13 +1..4 +ok 1 # SKIP insufficient flogiston pressure +ok 2 # SKIP no /sys directory +ok 3 # SKIP no /sys directory +` From 323dc3de8f66ea91fccd3f000379c39473cd73e4 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 11 Jan 2017 13:59:46 -0800 Subject: [PATCH 35/39] Add T.TODO and t.Todo() to drive the TODO directive The spec [1] suggests "not ok 13 # TODO ...", but if you attempt this with: t.Fail("# TODO foo") you get an extra hyphen ("not ok 13 - # TODO foo") which is parsed as a failed test (and not a TODO test). I'd initially written up an alternative to Ok: T.TODO(test bool, description string) but Michael pointed out that future work may add additional test methods (e.g. EqOk) and wanted to support those as well with something like [2]: t.TODO = true t.Ok(Foo(), "foo") t.EqOk(Bar(), Baz(), "bar == baz") t.TODO = false // could be done via defer too or [2]: t.TODO( func () { t.Ok(Foo(), "foo") t.EqOk(Bar(), Baz(), "bar == baz") }) This commit adds a .TODO boolean following Michael's first proposal. It also adds a Todo() method returning a copy of the test-state (but setting TODO), which you can use to avoid altering the original test-state's TODO value. This can be useful when you don't want to bother with a defer, or your TODO tests all live in an existing branch of a function, or you want to chain methods for a one-off TODO test: t.TODO().Ok(Foo(), "foo") To keep the count synchronized between sibling test states, nextTestNumber is now a pointer. We don't do anything to keep Writer synchronized, because it's already part of the public API as a non-pointer, and Michael is ok leaving this up to the caller [3]. [1]: http://testanything.org/tap-version-13-specification.html#todo-tests [2]: https://github.com/mndrix/tap-go/pull/6#issuecomment-272041306 [3]: https://github.com/mndrix/tap-go/pull/6#issuecomment-272318361 --- util/tap/Makefile | 2 +- util/tap/tap.go | 29 ++++++++++++++++++++++------- util/tap/test/todo/main.go | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 util/tap/test/todo/main.go diff --git a/util/tap/Makefile b/util/tap/Makefile index b06163f9..986541d7 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -1,4 +1,4 @@ -TESTS = auto check diagnostic failing known skip writer +TESTS = auto check diagnostic failing known skip todo writer GOPATH = $(CURDIR)/gopath .PHONY: $(TESTS) diff --git a/util/tap/tap.go b/util/tap/tap.go index fdc827d2..477fddc3 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -31,7 +31,10 @@ import "testing/quick" // T is a type to encapsulate test state. Methods on this type generate TAP // output. type T struct { - nextTestNumber int + nextTestNumber *int + + // TODO toggles the TODO directive for Ok, Fail, Pass, and similar. + TODO bool // Writer indicates where TAP output should be sent. The default is os.Stdout. Writer io.Writer @@ -39,8 +42,9 @@ type T struct { // New creates a new Tap value func New() *T { + nextTestNumber := 1 return &T{ - nextTestNumber: 1, + nextTestNumber: &nextTestNumber, } } @@ -74,8 +78,12 @@ func (t *T) Ok(test bool, description string) { ok = "not ok" } - t.printf("%s %d - %s\n", ok, t.nextTestNumber, description) - t.nextTestNumber++ + if t.TODO { + t.printf("%s %d # TODO %s\n", ok, *t.nextTestNumber, description) + } else { + t.printf("%s %d - %s\n", ok, *t.nextTestNumber, description) + } + (*t.nextTestNumber)++ } // Fail indicates that a test has failed. This is typically only used when the @@ -105,7 +113,7 @@ func (t *T) Check(function interface{}, description string) { // Count returns the number of tests completed so far. func (t *T) Count() int { - return t.nextTestNumber - 1 + return *t.nextTestNumber - 1 } // AutoPlan generates a test plan based on the number of tests that were run. @@ -117,11 +125,18 @@ func escapeNewlines(s string) string { return strings.Replace(strings.TrimRight(s, "\n"), "\n", "\n# ", -1) } +// Todo returns copy of the test-state with TODO set. +func (t *T) Todo() *T { + newT := *t + newT.TODO = true + return &newT +} + // Skip indicates that a test has been skipped. func (t *T) Skip(count int, description string) { for i := 0; i < count; i++ { - t.printf("ok %d # SKIP %s\n", t.nextTestNumber, description) - t.nextTestNumber++ + t.printf("ok %d # SKIP %s\n", *t.nextTestNumber, description) + (*t.nextTestNumber)++ } } diff --git a/util/tap/test/todo/main.go b/util/tap/test/todo/main.go new file mode 100644 index 00000000..943014c6 --- /dev/null +++ b/util/tap/test/todo/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "bytes" + "io" + "os" + + tap "github.com/mndrix/tap-go" +) + +func main() { + // collect output for comparison later + buf := new(bytes.Buffer) + t := tap.New() + t.Writer = io.MultiWriter(os.Stdout, buf) + + t.Header(6) + t.TODO = true + t.Ok(false, "using Ok(false, ...) in TODO mode") + t.Fail("using Fail(...) in TODO mode") + t.TODO = false + t.Ok(true, "using Ok(false, ...) after leaving TODO mode") + + t.Todo().Fail("using Fail(...) in TODO mode with method chaining") + t.Pass("using Pass(...) after Todo method chaining") + + got := buf.String() + t.Ok(got == expected, "TODO gave expected output") +} + +const expected = `TAP version 13 +1..6 +not ok 1 # TODO using Ok(false, ...) in TODO mode +not ok 2 # TODO using Fail(...) in TODO mode +ok 3 - using Ok(false, ...) after leaving TODO mode +not ok 4 # TODO using Fail(...) in TODO mode with method chaining +ok 5 - using Pass(...) after Todo method chaining +` From e1c4a836ef9c33b5db831d07dd4a932e58cac462 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 30 Nov 2017 10:56:18 -0800 Subject: [PATCH 36/39] Add YAML() for generating YAML blocks Docs in [1]. I've used Go's JSON serializer to avoid external dependencies, since JSON is a subset of YAML [2]. Prove is currently choking on the results: $ prove test/yaml/test test/yaml/test .. Failed 1/2 subtests Test Summary Report ------------------- test/yaml/test (Wstat: (none) Tests: 1 Failed: 0) Parse errors: Unsupported YAMLish syntax: '{' at /usr/lib64/perl5/5.22.3/TAP/Parser/YAMLish/Reader.pm line 101. Bad plan. You planned 2 tests but ran 1. Files=1, Tests=1, 0 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU) Result: FAIL $ prove --version TAP::Harness v3.35_01 and Perl v5.22.3 but node-tap [3] parses it fine: $ tap test/yaml/test test/yaml/test ........................................ 2/2 total ................................................. 2/2 2 passing (32.15ms) ok $ tap --version 11.0.0 [1]: https://testanything.org/tap-version-13-specification.html#yaml-blocks [2]: http://www.yaml.org/spec/1.2/spec.html $ curl -s http://www.yaml.org/spec/1.2/spec.html | grep -B1 JSON | head -n2 The primary objective of this revision is to bring YAML into compliance with JSON as an official subset. YAML 1.2 is compatible with 1.1 for [3]: http://www.node-tap.org/ --- util/tap/Makefile | 2 +- util/tap/tap.go | 13 +++++++++++++ util/tap/test/yaml/main.go | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 util/tap/test/yaml/main.go diff --git a/util/tap/Makefile b/util/tap/Makefile index 986541d7..6fabe627 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -1,4 +1,4 @@ -TESTS = auto check diagnostic failing known skip todo writer +TESTS = auto check diagnostic failing known skip todo writer yaml GOPATH = $(CURDIR)/gopath .PHONY: $(TESTS) diff --git a/util/tap/tap.go b/util/tap/tap.go index 477fddc3..5a07d7ff 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -21,6 +21,7 @@ package tap // import "github.com/mndrix/tap-go" import ( + "encoding/json" "fmt" "io" "os" @@ -151,3 +152,15 @@ func (t *T) Diagnostic(message string) { func (t *T) Diagnosticf(format string, a ...interface{}) { t.printf("# "+escapeNewlines(format)+"\n", a...) } + +// YAML generates a YAML block from the message. +func (t *T) YAML(message interface{}) error { + bytes, err := json.MarshalIndent(message, " ", " ") + if err != nil { + return err + } + t.printf(" ---\n ") + t.printf(string(bytes)) + t.printf("\n ...\n") + return nil +} diff --git a/util/tap/test/yaml/main.go b/util/tap/test/yaml/main.go new file mode 100644 index 00000000..21938cca --- /dev/null +++ b/util/tap/test/yaml/main.go @@ -0,0 +1,37 @@ +package main + +import ( + "bytes" + "io" + "os" + + tap "github.com/mndrix/tap-go" +) + +func main() { + // collect output for comparison later + buf := new(bytes.Buffer) + t := tap.New() + t.Writer = io.MultiWriter(os.Stdout, buf) + + t.Header(2) + t.Pass("test for anchoring the YAML block") + message := map[string]interface{}{ + "message": "testing YAML blocks", + "code": 3, + } + t.YAML(message) + got := buf.String() + t.Ok(got == expected, "diagnostics gave expected output") +} + +const expected = `TAP version 13 +1..2 +ok 1 - test for anchoring the YAML block + --- + { + "code": 3, + "message": "testing YAML blocks" + } + ... +` From 42b56ca4febaec8640fdf5906e9de1a38c22111d Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 1 Dec 2017 09:31:28 -0800 Subject: [PATCH 37/39] Add 'yaml' build tag for conditionally using gopkg.in/yaml.v2 So folks who are comfortable with the additional dependency can get prove-compatible output. Michael wants to stick with prove for tap-go because it is widely installed [1], but folks using node-tap or other consumers that can handle the JSON subset of YAML probably don't want the external dependency. Folks who want yaml.v2 can enable the yaml build tag [2]. Folks who are ok with JSON don't have to set any build tags. The go-yaml dependency is the only Go producer listed in [3]. There may be others, I haven't checked. The Makefile changes include new uses of wildcards [4] to pick up test/%/*.go siblings. And I'm using the stem variable $* [5] in the rule to pick up the whole test package (and not just main.go). I'm not sure how Michael wants vendoring to work. For the moment, I've softened the 'GOPATH =' to a 'GOPATH ?=' and installed the package in my local GOPATH. It's possible that we want to stick with 'GOPATH =' and drop the package under gopath/ (via a Git submodule?). [1]: https://github.com/mndrix/tap-go/pull/7#issuecomment-348424097 [2]: https://golang.org/pkg/go/build/#hdr-Build_Constraints [3]: http://yaml.org/ [4]: https://www.gnu.org/software/make/manual/html_node/Wildcard-Examples.html [5]: https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html --- util/tap/Makefile | 6 +++--- util/tap/tap.go | 5 ++--- util/tap/test/yaml/json.go | 14 ++++++++++++++ util/tap/test/yaml/main.go | 11 ----------- util/tap/test/yaml/yaml.go | 12 ++++++++++++ util/tap/yaml_json.go | 22 ++++++++++++++++++++++ util/tap/yaml_yaml.go | 23 +++++++++++++++++++++++ 7 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 util/tap/test/yaml/json.go create mode 100644 util/tap/test/yaml/yaml.go create mode 100644 util/tap/yaml_json.go create mode 100644 util/tap/yaml_yaml.go diff --git a/util/tap/Makefile b/util/tap/Makefile index 6fabe627..5911e250 100644 --- a/util/tap/Makefile +++ b/util/tap/Makefile @@ -1,5 +1,5 @@ TESTS = auto check diagnostic failing known skip todo writer yaml -GOPATH = $(CURDIR)/gopath +GOPATH ?= $(CURDIR)/gopath .PHONY: $(TESTS) @@ -9,8 +9,8 @@ all: $(foreach t,$(TESTS),test/$(t)/test) clean: rm -f test/*/test -test/%/test: test/%/main.go tap.go - go build -o $@ $< +test/%/test: test/%/*.go tap.go yaml_json.go yaml_yaml.go + go build -o $@ -tags yaml ./test/$* $(TESTS): %: test/%/test prove -v -e '' test/$@/test diff --git a/util/tap/tap.go b/util/tap/tap.go index 5a07d7ff..3be97065 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -21,7 +21,6 @@ package tap // import "github.com/mndrix/tap-go" import ( - "encoding/json" "fmt" "io" "os" @@ -155,12 +154,12 @@ func (t *T) Diagnosticf(format string, a ...interface{}) { // YAML generates a YAML block from the message. func (t *T) YAML(message interface{}) error { - bytes, err := json.MarshalIndent(message, " ", " ") + bytes, err := yaml(message, " ") if err != nil { return err } t.printf(" ---\n ") t.printf(string(bytes)) - t.printf("\n ...\n") + t.printf(" ...\n") return nil } diff --git a/util/tap/test/yaml/json.go b/util/tap/test/yaml/json.go new file mode 100644 index 00000000..09ee91c4 --- /dev/null +++ b/util/tap/test/yaml/json.go @@ -0,0 +1,14 @@ +// +build !yaml + +package main + +const expected = `TAP version 13 +1..2 +ok 1 - test for anchoring the YAML block + --- + { + "code": 3, + "message": "testing YAML blocks" + } + ... +` diff --git a/util/tap/test/yaml/main.go b/util/tap/test/yaml/main.go index 21938cca..895e3ad3 100644 --- a/util/tap/test/yaml/main.go +++ b/util/tap/test/yaml/main.go @@ -24,14 +24,3 @@ func main() { got := buf.String() t.Ok(got == expected, "diagnostics gave expected output") } - -const expected = `TAP version 13 -1..2 -ok 1 - test for anchoring the YAML block - --- - { - "code": 3, - "message": "testing YAML blocks" - } - ... -` diff --git a/util/tap/test/yaml/yaml.go b/util/tap/test/yaml/yaml.go new file mode 100644 index 00000000..d9824dff --- /dev/null +++ b/util/tap/test/yaml/yaml.go @@ -0,0 +1,12 @@ +// +build yaml + +package main + +const expected = `TAP version 13 +1..2 +ok 1 - test for anchoring the YAML block + --- + code: 3 + message: testing YAML blocks + ... +` diff --git a/util/tap/yaml_json.go b/util/tap/yaml_json.go new file mode 100644 index 00000000..f848e642 --- /dev/null +++ b/util/tap/yaml_json.go @@ -0,0 +1,22 @@ +// +build !yaml + +package tap + +import ( + "encoding/json" +) + +// yaml serializes a message to YAML. This implementation uses JSON, +// which is a subset of YAML [1] and is implemented by Go's standard +// library. +// +// [1]: http://www.yaml.org/spec/1.2/spec.html#id2759572 +func yaml(message interface{}, prefix string) (marshaled []byte, err error) { + marshaled, err = json.MarshalIndent(message, prefix, " ") + if err != nil { + return marshaled, err + } + + marshaled = append(marshaled, []byte("\n")...) + return marshaled, err +} diff --git a/util/tap/yaml_yaml.go b/util/tap/yaml_yaml.go new file mode 100644 index 00000000..93c6f2e8 --- /dev/null +++ b/util/tap/yaml_yaml.go @@ -0,0 +1,23 @@ +// +build yaml + +package tap + +import ( + "bytes" + + goyaml "gopkg.in/yaml.v2" +) + +// yaml serializes a message to YAML. This implementation uses +// non-JSON YAML, which has better prove support [1]. +// +// [1]: https://rt.cpan.org/Public/Bug/Display.html?id=121606 +func yaml(message interface{}, prefix string) (marshaled []byte, err error) { + marshaled, err = goyaml.Marshal(message) + if err != nil { + return marshaled, err + } + + marshaled = bytes.Replace(marshaled, []byte("\n"), []byte("\n"+prefix), -1) + return marshaled[:len(marshaled)-len(prefix)], err +} From b6301ac6f2430c2cc49a7b5bb5e50448884dcd17 Mon Sep 17 00:00:00 2001 From: "Muyassarov, Feruzjon" Date: Sat, 6 May 2023 00:13:46 +0300 Subject: [PATCH 38/39] Add a note about tap-go migration Signed-off-by: Muyassarov, Feruzjon --- util/tap/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util/tap/README.md b/util/tap/README.md index f795022d..46282062 100644 --- a/util/tap/README.md +++ b/util/tap/README.md @@ -5,3 +5,6 @@ interface between tests and a test harness. This package helps Go to generate TAP output. Read the [full package documentation](https://godoc.org/github.com/mndrix/tap-go) + +NOTE: This code was originally located at https://github.com/mndrix/tap-go and +migrated to here as thre project was archieved. \ No newline at end of file From cba200fce99ce135b2bfd221b631f91a5b69b83a Mon Sep 17 00:00:00 2001 From: "Muyassarov, Feruzjon" Date: Sat, 6 May 2023 10:23:32 +0300 Subject: [PATCH 39/39] Replace tap-go import path Signed-off-by: Muyassarov, Feruzjon --- cmd/runtimetest/main.go | 2 +- go.mod | 3 +- go.sum | 2 - util/tap/README.md | 4 +- util/tap/tap.go | 28 +-- util/tap/test/auto/main.go | 2 +- util/tap/test/check/main.go | 2 +- util/tap/test/diagnostic/main.go | 2 +- util/tap/test/failing/main.go | 2 +- util/tap/test/known/main.go | 2 +- util/tap/test/skip/main.go | 2 +- util/tap/test/todo/main.go | 2 +- util/tap/test/writer/main.go | 2 +- util/tap/test/yaml/main.go | 2 +- .../config_updates_without_affect.go | 2 +- validation/create/create.go | 2 +- validation/delete/delete.go | 4 +- .../delete_only_create_resources.go | 2 +- .../delete_resources/delete_resources.go | 4 +- validation/hooks/hooks.go | 2 +- validation/hooks_stdin/hooks_stdin.go | 2 +- validation/hostname/hostname.go | 2 +- validation/kill/kill.go | 4 +- validation/kill_no_effect/kill_no_effect.go | 4 +- validation/killsig/killsig.go | 4 +- .../linux_cgroups_blkio.go | 2 +- .../linux_cgroups_cpus/linux_cgroups_cpus.go | 2 +- .../linux_cgroups_devices.go | 2 +- .../linux_cgroups_hugetlb.go | 2 +- .../linux_cgroups_memory.go | 2 +- .../linux_cgroups_network.go | 2 +- .../linux_cgroups_pids/linux_cgroups_pids.go | 2 +- .../linux_cgroups_relative_blkio.go | 2 +- .../linux_cgroups_relative_cpus.go | 2 +- .../linux_cgroups_relative_devices.go | 2 +- .../linux_cgroups_relative_hugetlb.go | 2 +- .../linux_cgroups_relative_memory.go | 2 +- .../linux_cgroups_relative_network.go | 2 +- .../linux_cgroups_relative_pids.go | 2 +- .../linux_masked_paths/linux_masked_paths.go | 2 +- validation/linux_ns_itype/linux_ns_itype.go | 2 +- validation/linux_ns_nopath/linux_ns_nopath.go | 2 +- validation/linux_ns_path/linux_ns_path.go | 2 +- .../linux_ns_path_type/linux_ns_path_type.go | 2 +- .../linux_readonly_paths.go | 2 +- .../linux_rootfs_propagation.go | 2 +- validation/linux_seccomp/linux_seccomp.go | 2 +- validation/misc_props/misc_props.go | 2 +- validation/pidfile/pidfile.go | 2 +- validation/poststart/poststart.go | 2 +- validation/poststart_fail/poststart_fail.go | 2 +- validation/poststop/poststop.go | 2 +- validation/poststop_fail/poststop_fail.go | 2 +- validation/prestart/prestart.go | 2 +- validation/prestart_fail/prestart_fail.go | 4 +- validation/start/start.go | 2 +- validation/state/state.go | 4 +- validation/util/linux_resources_blkio.go | 2 +- validation/util/linux_resources_cpus.go | 2 +- validation/util/linux_resources_devices.go | 2 +- validation/util/linux_resources_memory.go | 2 +- validation/util/linux_resources_network.go | 2 +- validation/util/linux_resources_pids.go | 2 +- validation/util/test.go | 2 +- vendor/github.com/mndrix/tap-go/.gitignore | 3 - vendor/github.com/mndrix/tap-go/LICENSE | 24 --- vendor/github.com/mndrix/tap-go/Makefile | 16 -- vendor/github.com/mndrix/tap-go/README.md | 7 - vendor/github.com/mndrix/tap-go/tap.go | 165 ------------------ vendor/github.com/mndrix/tap-go/yaml_json.go | 22 --- vendor/github.com/mndrix/tap-go/yaml_yaml.go | 23 --- vendor/modules.txt | 3 - 72 files changed, 84 insertions(+), 350 deletions(-) delete mode 100644 vendor/github.com/mndrix/tap-go/.gitignore delete mode 100644 vendor/github.com/mndrix/tap-go/LICENSE delete mode 100644 vendor/github.com/mndrix/tap-go/Makefile delete mode 100644 vendor/github.com/mndrix/tap-go/README.md delete mode 100644 vendor/github.com/mndrix/tap-go/tap.go delete mode 100644 vendor/github.com/mndrix/tap-go/yaml_json.go delete mode 100644 vendor/github.com/mndrix/tap-go/yaml_yaml.go diff --git a/cmd/runtimetest/main.go b/cmd/runtimetest/main.go index 3aa3370c..4684e327 100644 --- a/cmd/runtimetest/main.go +++ b/cmd/runtimetest/main.go @@ -14,8 +14,8 @@ import ( "strings" "syscall" - "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/sirupsen/logrus" "github.com/syndtr/gocapability/capability" "github.com/urfave/cli" diff --git a/go.mod b/go.mod index 1368e7c8..09f3ecad 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/blang/semver/v4 v4.0.0 github.com/google/uuid v1.3.0 github.com/hashicorp/go-multierror v1.1.1 - github.com/mndrix/tap-go v0.0.0-20171203230836-629fa407e90b github.com/mrunalp/fileutils v0.5.0 github.com/opencontainers/runtime-spec v1.0.3-0.20220825212826-86290f6a00fb github.com/opencontainers/selinux v1.9.1 @@ -16,6 +15,7 @@ require ( github.com/urfave/cli v1.19.1 github.com/xeipuuv/gojsonschema v1.2.0 golang.org/x/sys v0.0.0-20191115151921-52ab43148777 + gopkg.in/yaml.v2 v2.4.0 ) require ( @@ -24,5 +24,4 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 37ddcdd4..d13140d7 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,6 @@ github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/U github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/mndrix/tap-go v0.0.0-20171203230836-629fa407e90b h1:Ga1nclDSe8gOw37MVLMhfu2QKWtD6gvtQ298zsKVh8g= -github.com/mndrix/tap-go v0.0.0-20171203230836-629fa407e90b/go.mod h1:pzzDgJWZ34fGzaAZGFW22KVZDfyrYW+QABMrWnJBnSs= github.com/mrunalp/fileutils v0.5.0 h1:NKzVxiH7eSk+OQ4M+ZYW1K6h27RUV3MI6NUTsHhU6Z4= github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= github.com/opencontainers/runtime-spec v1.0.3-0.20220825212826-86290f6a00fb h1:1xSVPOd7/UA+39/hXEGnBJ13p6JFB0E1EvQFlrRDOXI= diff --git a/util/tap/README.md b/util/tap/README.md index 46282062..9b722bdd 100644 --- a/util/tap/README.md +++ b/util/tap/README.md @@ -4,7 +4,7 @@ The [Test Anything Protocol](http://testanything.org/) ("TAP") is a text-based interface between tests and a test harness. This package helps Go to generate TAP output. -Read the [full package documentation](https://godoc.org/github.com/mndrix/tap-go) +Read the [full package documentation](https://godoc.org/github.com/opencontainers/runtime-tools/util/tap) NOTE: This code was originally located at https://github.com/mndrix/tap-go and -migrated to here as thre project was archieved. \ No newline at end of file +migrated to here as the project was archieved. \ No newline at end of file diff --git a/util/tap/tap.go b/util/tap/tap.go index 3be97065..b40237bb 100644 --- a/util/tap/tap.go +++ b/util/tap/tap.go @@ -1,32 +1,32 @@ // Package tap provides support for automated Test Anything Protocol ("TAP") // tests in Go. For example: // -// package main +// package main // -// import "github.com/mndrix/tap-go" +// import "github.com/opencontainers/runtime-tools/util/tap" // -// func main() { -// t := tap.New() -// t.Header(2) -// t.Ok(true, "first test") -// t.Ok(true, "second test") -// } +// func main() { +// t := tap.New() +// t.Header(2) +// t.Ok(true, "first test") +// t.Ok(true, "second test") +// } // // generates the following output // -// TAP version 13 -// 1..2 -// ok 1 - first test -// ok 2 - second test -package tap // import "github.com/mndrix/tap-go" +// TAP version 13 +// 1..2 +// ok 1 - first test +// ok 2 - second test +package tap import ( "fmt" "io" "os" "strings" + "testing/quick" ) -import "testing/quick" // T is a type to encapsulate test state. Methods on this type generate TAP // output. diff --git a/util/tap/test/auto/main.go b/util/tap/test/auto/main.go index 24dc4809..6c654a67 100644 --- a/util/tap/test/auto/main.go +++ b/util/tap/test/auto/main.go @@ -1,6 +1,6 @@ package main -import "github.com/mndrix/tap-go" +import "github.com/opencontainers/runtime-tools/util/tap" func main() { t := tap.New() diff --git a/util/tap/test/check/main.go b/util/tap/test/check/main.go index d780e0d5..0258f4d4 100644 --- a/util/tap/test/check/main.go +++ b/util/tap/test/check/main.go @@ -1,6 +1,6 @@ package main -import "github.com/mndrix/tap-go" +import "github.com/opencontainers/runtime-tools/util/tap" func main() { add := func(x int) bool { return x+3 > x } diff --git a/util/tap/test/diagnostic/main.go b/util/tap/test/diagnostic/main.go index 6d3b458f..1cad82f1 100644 --- a/util/tap/test/diagnostic/main.go +++ b/util/tap/test/diagnostic/main.go @@ -5,7 +5,7 @@ import ( "io" "os" - tap "github.com/mndrix/tap-go" + tap "github.com/opencontainers/runtime-tools/util/tap" ) func main() { diff --git a/util/tap/test/failing/main.go b/util/tap/test/failing/main.go index 5b768662..484a5600 100644 --- a/util/tap/test/failing/main.go +++ b/util/tap/test/failing/main.go @@ -3,7 +3,7 @@ package main import ( "bytes" - "github.com/mndrix/tap-go" + "github.com/opencontainers/runtime-tools/util/tap" ) func main() { diff --git a/util/tap/test/known/main.go b/util/tap/test/known/main.go index 5714f799..5969e099 100644 --- a/util/tap/test/known/main.go +++ b/util/tap/test/known/main.go @@ -1,6 +1,6 @@ package main -import "github.com/mndrix/tap-go" +import "github.com/opencontainers/runtime-tools/util/tap" func main() { t := tap.New() diff --git a/util/tap/test/skip/main.go b/util/tap/test/skip/main.go index 5bc2161c..632d293d 100644 --- a/util/tap/test/skip/main.go +++ b/util/tap/test/skip/main.go @@ -5,7 +5,7 @@ import ( "io" "os" - tap "github.com/mndrix/tap-go" + tap "github.com/opencontainers/runtime-tools/util/tap" ) func main() { diff --git a/util/tap/test/todo/main.go b/util/tap/test/todo/main.go index 943014c6..db67966e 100644 --- a/util/tap/test/todo/main.go +++ b/util/tap/test/todo/main.go @@ -5,7 +5,7 @@ import ( "io" "os" - tap "github.com/mndrix/tap-go" + tap "github.com/opencontainers/runtime-tools/util/tap" ) func main() { diff --git a/util/tap/test/writer/main.go b/util/tap/test/writer/main.go index 11f826df..856c5880 100644 --- a/util/tap/test/writer/main.go +++ b/util/tap/test/writer/main.go @@ -4,7 +4,7 @@ import ( "bytes" "os" - "github.com/mndrix/tap-go" + "github.com/opencontainers/runtime-tools/util/tap" ) func main() { diff --git a/util/tap/test/yaml/main.go b/util/tap/test/yaml/main.go index 895e3ad3..cbd87c45 100644 --- a/util/tap/test/yaml/main.go +++ b/util/tap/test/yaml/main.go @@ -5,7 +5,7 @@ import ( "io" "os" - tap "github.com/mndrix/tap-go" + tap "github.com/opencontainers/runtime-tools/util/tap" ) func main() { diff --git a/validation/config_updates_without_affect/config_updates_without_affect.go b/validation/config_updates_without_affect/config_updates_without_affect.go index d3663c27..a9f52be7 100644 --- a/validation/config_updates_without_affect/config_updates_without_affect.go +++ b/validation/config_updates_without_affect/config_updates_without_affect.go @@ -7,11 +7,11 @@ import ( "time" "github.com/google/uuid" - tap "github.com/mndrix/tap-go" "github.com/mrunalp/fileutils" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/generate" "github.com/opencontainers/runtime-tools/specerror" + tap "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/create/create.go b/validation/create/create.go index 3c0e0d6c..9438d9d8 100644 --- a/validation/create/create.go +++ b/validation/create/create.go @@ -6,10 +6,10 @@ import ( "runtime" "github.com/google/uuid" - "github.com/mndrix/tap-go" rspecs "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/generate" "github.com/opencontainers/runtime-tools/specerror" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/delete/delete.go b/validation/delete/delete.go index 01467d43..fd1a86bb 100644 --- a/validation/delete/delete.go +++ b/validation/delete/delete.go @@ -5,12 +5,12 @@ import ( "os" "time" - "github.com/mndrix/tap-go" + "github.com/google/uuid" rspecs "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/generate" "github.com/opencontainers/runtime-tools/specerror" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" - "github.com/google/uuid" ) func main() { diff --git a/validation/delete_only_create_resources/delete_only_create_resources.go b/validation/delete_only_create_resources/delete_only_create_resources.go index 7f78b638..91cbb573 100644 --- a/validation/delete_only_create_resources/delete_only_create_resources.go +++ b/validation/delete_only_create_resources/delete_only_create_resources.go @@ -8,10 +8,10 @@ import ( "time" "github.com/google/uuid" - tap "github.com/mndrix/tap-go" "github.com/mrunalp/fileutils" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + tap "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/delete_resources/delete_resources.go b/validation/delete_resources/delete_resources.go index b0308275..1f3aabd6 100644 --- a/validation/delete_resources/delete_resources.go +++ b/validation/delete_resources/delete_resources.go @@ -6,13 +6,13 @@ import ( "path/filepath" "time" - tap "github.com/mndrix/tap-go" + "github.com/google/uuid" "github.com/mrunalp/fileutils" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/cgroups" "github.com/opencontainers/runtime-tools/specerror" + tap "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" - "github.com/google/uuid" ) func main() { diff --git a/validation/hooks/hooks.go b/validation/hooks/hooks.go index f039a073..1f6d70c8 100644 --- a/validation/hooks/hooks.go +++ b/validation/hooks/hooks.go @@ -8,9 +8,9 @@ import ( "time" "github.com/google/uuid" - tap "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + tap "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/hooks_stdin/hooks_stdin.go b/validation/hooks_stdin/hooks_stdin.go index d5a95ff2..492ea04c 100644 --- a/validation/hooks_stdin/hooks_stdin.go +++ b/validation/hooks_stdin/hooks_stdin.go @@ -11,9 +11,9 @@ import ( "github.com/google/uuid" multierror "github.com/hashicorp/go-multierror" - tap "github.com/mndrix/tap-go" rspecs "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + tap "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/hostname/hostname.go b/validation/hostname/hostname.go index 02e01754..5c9bfaed 100644 --- a/validation/hostname/hostname.go +++ b/validation/hostname/hostname.go @@ -4,7 +4,7 @@ import ( "fmt" "runtime" - "github.com/mndrix/tap-go" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/kill/kill.go b/validation/kill/kill.go index ad533669..cf945e0c 100644 --- a/validation/kill/kill.go +++ b/validation/kill/kill.go @@ -5,12 +5,12 @@ import ( "os" "time" - "github.com/mndrix/tap-go" + "github.com/google/uuid" rspecs "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/generate" "github.com/opencontainers/runtime-tools/specerror" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" - "github.com/google/uuid" ) func main() { diff --git a/validation/kill_no_effect/kill_no_effect.go b/validation/kill_no_effect/kill_no_effect.go index 7d0b35ab..0462dafe 100644 --- a/validation/kill_no_effect/kill_no_effect.go +++ b/validation/kill_no_effect/kill_no_effect.go @@ -6,11 +6,11 @@ import ( "reflect" "time" - "github.com/mndrix/tap-go" + "github.com/google/uuid" rspecs "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" - "github.com/google/uuid" ) func main() { diff --git a/validation/killsig/killsig.go b/validation/killsig/killsig.go index a3bd49e3..4c493ccf 100644 --- a/validation/killsig/killsig.go +++ b/validation/killsig/killsig.go @@ -6,11 +6,11 @@ import ( "path/filepath" "time" - "github.com/mndrix/tap-go" + "github.com/google/uuid" rspecs "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" - "github.com/google/uuid" ) var signals = []string{ diff --git a/validation/linux_cgroups_blkio/linux_cgroups_blkio.go b/validation/linux_cgroups_blkio/linux_cgroups_blkio.go index 5b335f50..7535f9f1 100644 --- a/validation/linux_cgroups_blkio/linux_cgroups_blkio.go +++ b/validation/linux_cgroups_blkio/linux_cgroups_blkio.go @@ -4,8 +4,8 @@ import ( "fmt" "runtime" - "github.com/mndrix/tap-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_cgroups_cpus/linux_cgroups_cpus.go b/validation/linux_cgroups_cpus/linux_cgroups_cpus.go index a1370758..a550da64 100644 --- a/validation/linux_cgroups_cpus/linux_cgroups_cpus.go +++ b/validation/linux_cgroups_cpus/linux_cgroups_cpus.go @@ -6,8 +6,8 @@ import ( "path/filepath" "runtime" - "github.com/mndrix/tap-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_cgroups_devices/linux_cgroups_devices.go b/validation/linux_cgroups_devices/linux_cgroups_devices.go index ae947ade..e3e9047c 100644 --- a/validation/linux_cgroups_devices/linux_cgroups_devices.go +++ b/validation/linux_cgroups_devices/linux_cgroups_devices.go @@ -1,8 +1,8 @@ package main import ( - "github.com/mndrix/tap-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_cgroups_hugetlb/linux_cgroups_hugetlb.go b/validation/linux_cgroups_hugetlb/linux_cgroups_hugetlb.go index e1db3f1b..5fb3f273 100644 --- a/validation/linux_cgroups_hugetlb/linux_cgroups_hugetlb.go +++ b/validation/linux_cgroups_hugetlb/linux_cgroups_hugetlb.go @@ -4,9 +4,9 @@ import ( "fmt" "runtime" - "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_cgroups_memory/linux_cgroups_memory.go b/validation/linux_cgroups_memory/linux_cgroups_memory.go index 89e88bd7..1649296b 100644 --- a/validation/linux_cgroups_memory/linux_cgroups_memory.go +++ b/validation/linux_cgroups_memory/linux_cgroups_memory.go @@ -4,8 +4,8 @@ import ( "fmt" "runtime" - "github.com/mndrix/tap-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_cgroups_network/linux_cgroups_network.go b/validation/linux_cgroups_network/linux_cgroups_network.go index f91cf986..37d75009 100644 --- a/validation/linux_cgroups_network/linux_cgroups_network.go +++ b/validation/linux_cgroups_network/linux_cgroups_network.go @@ -5,8 +5,8 @@ import ( "net" "runtime" - "github.com/mndrix/tap-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_cgroups_pids/linux_cgroups_pids.go b/validation/linux_cgroups_pids/linux_cgroups_pids.go index 5826c6ae..81492312 100644 --- a/validation/linux_cgroups_pids/linux_cgroups_pids.go +++ b/validation/linux_cgroups_pids/linux_cgroups_pids.go @@ -1,8 +1,8 @@ package main import ( - "github.com/mndrix/tap-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_cgroups_relative_blkio/linux_cgroups_relative_blkio.go b/validation/linux_cgroups_relative_blkio/linux_cgroups_relative_blkio.go index 67b0433e..9c3f11fe 100644 --- a/validation/linux_cgroups_relative_blkio/linux_cgroups_relative_blkio.go +++ b/validation/linux_cgroups_relative_blkio/linux_cgroups_relative_blkio.go @@ -1,8 +1,8 @@ package main import ( - "github.com/mndrix/tap-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_cgroups_relative_cpus/linux_cgroups_relative_cpus.go b/validation/linux_cgroups_relative_cpus/linux_cgroups_relative_cpus.go index 29086075..afe4b6e5 100644 --- a/validation/linux_cgroups_relative_cpus/linux_cgroups_relative_cpus.go +++ b/validation/linux_cgroups_relative_cpus/linux_cgroups_relative_cpus.go @@ -1,9 +1,9 @@ package main import ( - "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_cgroups_relative_devices/linux_cgroups_relative_devices.go b/validation/linux_cgroups_relative_devices/linux_cgroups_relative_devices.go index 679a88f2..0134a665 100644 --- a/validation/linux_cgroups_relative_devices/linux_cgroups_relative_devices.go +++ b/validation/linux_cgroups_relative_devices/linux_cgroups_relative_devices.go @@ -1,8 +1,8 @@ package main import ( - "github.com/mndrix/tap-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_cgroups_relative_hugetlb/linux_cgroups_relative_hugetlb.go b/validation/linux_cgroups_relative_hugetlb/linux_cgroups_relative_hugetlb.go index 583a9fa8..04002e18 100644 --- a/validation/linux_cgroups_relative_hugetlb/linux_cgroups_relative_hugetlb.go +++ b/validation/linux_cgroups_relative_hugetlb/linux_cgroups_relative_hugetlb.go @@ -2,9 +2,9 @@ package main import ( "fmt" - "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_cgroups_relative_memory/linux_cgroups_relative_memory.go b/validation/linux_cgroups_relative_memory/linux_cgroups_relative_memory.go index 7dcdeb27..5562ee57 100644 --- a/validation/linux_cgroups_relative_memory/linux_cgroups_relative_memory.go +++ b/validation/linux_cgroups_relative_memory/linux_cgroups_relative_memory.go @@ -1,8 +1,8 @@ package main import ( - "github.com/mndrix/tap-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_cgroups_relative_network/linux_cgroups_relative_network.go b/validation/linux_cgroups_relative_network/linux_cgroups_relative_network.go index da5e9ee2..025b6cf5 100644 --- a/validation/linux_cgroups_relative_network/linux_cgroups_relative_network.go +++ b/validation/linux_cgroups_relative_network/linux_cgroups_relative_network.go @@ -1,8 +1,8 @@ package main import ( - "github.com/mndrix/tap-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_cgroups_relative_pids/linux_cgroups_relative_pids.go b/validation/linux_cgroups_relative_pids/linux_cgroups_relative_pids.go index 6a9c90f7..85e82220 100644 --- a/validation/linux_cgroups_relative_pids/linux_cgroups_relative_pids.go +++ b/validation/linux_cgroups_relative_pids/linux_cgroups_relative_pids.go @@ -1,8 +1,8 @@ package main import ( - "github.com/mndrix/tap-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_masked_paths/linux_masked_paths.go b/validation/linux_masked_paths/linux_masked_paths.go index 1345a6ad..69cd1791 100644 --- a/validation/linux_masked_paths/linux_masked_paths.go +++ b/validation/linux_masked_paths/linux_masked_paths.go @@ -5,7 +5,7 @@ import ( "os" "path/filepath" - "github.com/mndrix/tap-go" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" "golang.org/x/sys/unix" ) diff --git a/validation/linux_ns_itype/linux_ns_itype.go b/validation/linux_ns_itype/linux_ns_itype.go index 1b08b458..33828d04 100644 --- a/validation/linux_ns_itype/linux_ns_itype.go +++ b/validation/linux_ns_itype/linux_ns_itype.go @@ -6,9 +6,9 @@ import ( "path/filepath" "runtime" - "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_ns_nopath/linux_ns_nopath.go b/validation/linux_ns_nopath/linux_ns_nopath.go index 7aea78d0..91053d85 100644 --- a/validation/linux_ns_nopath/linux_ns_nopath.go +++ b/validation/linux_ns_nopath/linux_ns_nopath.go @@ -6,9 +6,9 @@ import ( "path/filepath" "runtime" - "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_ns_path/linux_ns_path.go b/validation/linux_ns_path/linux_ns_path.go index 8744fb59..bf358c70 100644 --- a/validation/linux_ns_path/linux_ns_path.go +++ b/validation/linux_ns_path/linux_ns_path.go @@ -8,9 +8,9 @@ import ( "syscall" "time" - "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_ns_path_type/linux_ns_path_type.go b/validation/linux_ns_path_type/linux_ns_path_type.go index 82846831..8db0f8b1 100644 --- a/validation/linux_ns_path_type/linux_ns_path_type.go +++ b/validation/linux_ns_path_type/linux_ns_path_type.go @@ -6,9 +6,9 @@ import ( "runtime" "syscall" - "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_readonly_paths/linux_readonly_paths.go b/validation/linux_readonly_paths/linux_readonly_paths.go index 2427060c..b0b01afb 100644 --- a/validation/linux_readonly_paths/linux_readonly_paths.go +++ b/validation/linux_readonly_paths/linux_readonly_paths.go @@ -5,7 +5,7 @@ import ( "os" "path/filepath" - "github.com/mndrix/tap-go" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" "golang.org/x/sys/unix" ) diff --git a/validation/linux_rootfs_propagation/linux_rootfs_propagation.go b/validation/linux_rootfs_propagation/linux_rootfs_propagation.go index 5938aea6..631d99af 100644 --- a/validation/linux_rootfs_propagation/linux_rootfs_propagation.go +++ b/validation/linux_rootfs_propagation/linux_rootfs_propagation.go @@ -1,7 +1,7 @@ package main import ( - "github.com/mndrix/tap-go" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/linux_seccomp/linux_seccomp.go b/validation/linux_seccomp/linux_seccomp.go index 5bbf716d..9a96d1c0 100644 --- a/validation/linux_seccomp/linux_seccomp.go +++ b/validation/linux_seccomp/linux_seccomp.go @@ -1,8 +1,8 @@ package main import ( - tap "github.com/mndrix/tap-go" "github.com/opencontainers/runtime-tools/generate/seccomp" + tap "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/misc_props/misc_props.go b/validation/misc_props/misc_props.go index bbcfaff5..85e8cf3e 100644 --- a/validation/misc_props/misc_props.go +++ b/validation/misc_props/misc_props.go @@ -8,9 +8,9 @@ import ( "time" "github.com/google/uuid" - "github.com/mndrix/tap-go" rspecs "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/pidfile/pidfile.go b/validation/pidfile/pidfile.go index 45adfbca..a6afa87a 100644 --- a/validation/pidfile/pidfile.go +++ b/validation/pidfile/pidfile.go @@ -9,7 +9,7 @@ import ( "time" "github.com/google/uuid" - tap "github.com/mndrix/tap-go" + tap "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/poststart/poststart.go b/validation/poststart/poststart.go index b3d9452a..aa2bf958 100644 --- a/validation/poststart/poststart.go +++ b/validation/poststart/poststart.go @@ -9,9 +9,9 @@ import ( "time" "github.com/google/uuid" - tap "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + tap "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/poststart_fail/poststart_fail.go b/validation/poststart_fail/poststart_fail.go index 82d922b0..69be4207 100644 --- a/validation/poststart_fail/poststart_fail.go +++ b/validation/poststart_fail/poststart_fail.go @@ -7,9 +7,9 @@ import ( "time" "github.com/google/uuid" - tap "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + tap "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/poststop/poststop.go b/validation/poststop/poststop.go index 87bd565e..661283a1 100644 --- a/validation/poststop/poststop.go +++ b/validation/poststop/poststop.go @@ -10,9 +10,9 @@ import ( "time" "github.com/google/uuid" - tap "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + tap "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/poststop_fail/poststop_fail.go b/validation/poststop_fail/poststop_fail.go index 0d85ab77..31e22af7 100644 --- a/validation/poststop_fail/poststop_fail.go +++ b/validation/poststop_fail/poststop_fail.go @@ -7,9 +7,9 @@ import ( "time" "github.com/google/uuid" - tap "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + tap "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/prestart/prestart.go b/validation/prestart/prestart.go index 92bf2216..29110685 100644 --- a/validation/prestart/prestart.go +++ b/validation/prestart/prestart.go @@ -9,9 +9,9 @@ import ( "time" "github.com/google/uuid" - tap "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + tap "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/prestart_fail/prestart_fail.go b/validation/prestart_fail/prestart_fail.go index d18175ec..1157e519 100644 --- a/validation/prestart_fail/prestart_fail.go +++ b/validation/prestart_fail/prestart_fail.go @@ -5,11 +5,11 @@ import ( "os" "path/filepath" - tap "github.com/mndrix/tap-go" + "github.com/google/uuid" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + tap "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" - "github.com/google/uuid" ) func main() { diff --git a/validation/start/start.go b/validation/start/start.go index 07895d8e..a9c0fa48 100644 --- a/validation/start/start.go +++ b/validation/start/start.go @@ -7,9 +7,9 @@ import ( "time" "github.com/google/uuid" - "github.com/mndrix/tap-go" rspecs "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/specerror" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" ) diff --git a/validation/state/state.go b/validation/state/state.go index 5d688ff4..f63d3cab 100644 --- a/validation/state/state.go +++ b/validation/state/state.go @@ -5,12 +5,12 @@ import ( "os/exec" "time" - "github.com/mndrix/tap-go" + "github.com/google/uuid" rspecs "github.com/opencontainers/runtime-spec/specs-go" rfc2119 "github.com/opencontainers/runtime-tools/error" "github.com/opencontainers/runtime-tools/specerror" + "github.com/opencontainers/runtime-tools/util/tap" "github.com/opencontainers/runtime-tools/validation/util" - "github.com/google/uuid" ) func main() { diff --git a/validation/util/linux_resources_blkio.go b/validation/util/linux_resources_blkio.go index 1d4ac12f..8eceda67 100644 --- a/validation/util/linux_resources_blkio.go +++ b/validation/util/linux_resources_blkio.go @@ -3,9 +3,9 @@ package util import ( "fmt" - "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" ) // ValidateLinuxResourcesBlockIO validates linux.resources.blockIO. diff --git a/validation/util/linux_resources_cpus.go b/validation/util/linux_resources_cpus.go index f37efe9a..c944ca05 100644 --- a/validation/util/linux_resources_cpus.go +++ b/validation/util/linux_resources_cpus.go @@ -8,9 +8,9 @@ import ( "strconv" "strings" - "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" ) const ( diff --git a/validation/util/linux_resources_devices.go b/validation/util/linux_resources_devices.go index ed755168..3489ab80 100644 --- a/validation/util/linux_resources_devices.go +++ b/validation/util/linux_resources_devices.go @@ -3,10 +3,10 @@ package util import ( "fmt" - "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/cgroups" "github.com/opencontainers/runtime-tools/specerror" + "github.com/opencontainers/runtime-tools/util/tap" ) // ValidateLinuxResourcesDevices validates linux.resources.devices. diff --git a/validation/util/linux_resources_memory.go b/validation/util/linux_resources_memory.go index 73de149d..939d7edf 100644 --- a/validation/util/linux_resources_memory.go +++ b/validation/util/linux_resources_memory.go @@ -1,9 +1,9 @@ package util import ( - "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" ) // ValidateLinuxResourcesMemory validates linux.resources.memory. diff --git a/validation/util/linux_resources_network.go b/validation/util/linux_resources_network.go index 22682413..4394e909 100644 --- a/validation/util/linux_resources_network.go +++ b/validation/util/linux_resources_network.go @@ -3,9 +3,9 @@ package util import ( "fmt" - "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" ) // ValidateLinuxResourcesNetwork validates linux.resources.network. diff --git a/validation/util/linux_resources_pids.go b/validation/util/linux_resources_pids.go index 1431efd9..f55dbc26 100644 --- a/validation/util/linux_resources_pids.go +++ b/validation/util/linux_resources_pids.go @@ -1,9 +1,9 @@ package util import ( - "github.com/mndrix/tap-go" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/cgroups" + "github.com/opencontainers/runtime-tools/util/tap" ) // ValidateLinuxResourcesPids validates linux.resources.pids. diff --git a/validation/util/test.go b/validation/util/test.go index 626499e6..b8537ab2 100644 --- a/validation/util/test.go +++ b/validation/util/test.go @@ -11,11 +11,11 @@ import ( "time" "github.com/google/uuid" - "github.com/mndrix/tap-go" "github.com/mrunalp/fileutils" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/generate" "github.com/opencontainers/runtime-tools/specerror" + "github.com/opencontainers/runtime-tools/util/tap" ) // RuntimeCommand is the default runtime command. diff --git a/vendor/github.com/mndrix/tap-go/.gitignore b/vendor/github.com/mndrix/tap-go/.gitignore deleted file mode 100644 index 9e8d7ca0..00000000 --- a/vendor/github.com/mndrix/tap-go/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -gopath/pkg -test/*/test -/TAGS diff --git a/vendor/github.com/mndrix/tap-go/LICENSE b/vendor/github.com/mndrix/tap-go/LICENSE deleted file mode 100644 index cf1ab25d..00000000 --- a/vendor/github.com/mndrix/tap-go/LICENSE +++ /dev/null @@ -1,24 +0,0 @@ -This is free and unencumbered software released into the public domain. - -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. - -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -For more information, please refer to diff --git a/vendor/github.com/mndrix/tap-go/Makefile b/vendor/github.com/mndrix/tap-go/Makefile deleted file mode 100644 index 5911e250..00000000 --- a/vendor/github.com/mndrix/tap-go/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -TESTS = auto check diagnostic failing known skip todo writer yaml -GOPATH ?= $(CURDIR)/gopath - -.PHONY: $(TESTS) - -all: $(foreach t,$(TESTS),test/$(t)/test) - prove -v -e '' test/*/test - -clean: - rm -f test/*/test - -test/%/test: test/%/*.go tap.go yaml_json.go yaml_yaml.go - go build -o $@ -tags yaml ./test/$* - -$(TESTS): %: test/%/test - prove -v -e '' test/$@/test diff --git a/vendor/github.com/mndrix/tap-go/README.md b/vendor/github.com/mndrix/tap-go/README.md deleted file mode 100644 index f795022d..00000000 --- a/vendor/github.com/mndrix/tap-go/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Test Anything Protocol for Go - -The [Test Anything Protocol](http://testanything.org/) ("TAP") is a text-based -interface between tests and a test harness. This package helps Go to generate -TAP output. - -Read the [full package documentation](https://godoc.org/github.com/mndrix/tap-go) diff --git a/vendor/github.com/mndrix/tap-go/tap.go b/vendor/github.com/mndrix/tap-go/tap.go deleted file mode 100644 index 3be97065..00000000 --- a/vendor/github.com/mndrix/tap-go/tap.go +++ /dev/null @@ -1,165 +0,0 @@ -// Package tap provides support for automated Test Anything Protocol ("TAP") -// tests in Go. For example: -// -// package main -// -// import "github.com/mndrix/tap-go" -// -// func main() { -// t := tap.New() -// t.Header(2) -// t.Ok(true, "first test") -// t.Ok(true, "second test") -// } -// -// generates the following output -// -// TAP version 13 -// 1..2 -// ok 1 - first test -// ok 2 - second test -package tap // import "github.com/mndrix/tap-go" - -import ( - "fmt" - "io" - "os" - "strings" -) -import "testing/quick" - -// T is a type to encapsulate test state. Methods on this type generate TAP -// output. -type T struct { - nextTestNumber *int - - // TODO toggles the TODO directive for Ok, Fail, Pass, and similar. - TODO bool - - // Writer indicates where TAP output should be sent. The default is os.Stdout. - Writer io.Writer -} - -// New creates a new Tap value -func New() *T { - nextTestNumber := 1 - return &T{ - nextTestNumber: &nextTestNumber, - } -} - -func (t *T) w() io.Writer { - if t.Writer == nil { - return os.Stdout - } - return t.Writer -} - -func (t *T) printf(format string, a ...interface{}) { - fmt.Fprintf(t.w(), format, a...) -} - -// Header displays a TAP header including version number and expected -// number of tests to run. For an unknown number of tests, set -// testCount to zero (in which case the plan is not written); this is -// useful with AutoPlan. -func (t *T) Header(testCount int) { - t.printf("TAP version 13\n") - if testCount > 0 { - t.printf("1..%d\n", testCount) - } -} - -// Ok generates TAP output indicating whether a test passed or failed. -func (t *T) Ok(test bool, description string) { - // did the test pass or not? - ok := "ok" - if !test { - ok = "not ok" - } - - if t.TODO { - t.printf("%s %d # TODO %s\n", ok, *t.nextTestNumber, description) - } else { - t.printf("%s %d - %s\n", ok, *t.nextTestNumber, description) - } - (*t.nextTestNumber)++ -} - -// Fail indicates that a test has failed. This is typically only used when the -// logic is too complex to fit naturally into an Ok() call. -func (t *T) Fail(description string) { - t.Ok(false, description) -} - -// Pass indicates that a test has passed. This is typically only used when the -// logic is too complex to fit naturally into an Ok() call. -func (t *T) Pass(description string) { - t.Ok(true, description) -} - -// Check runs randomized tests against a function just as "testing/quick.Check" -// does. Success or failure generate appropriate TAP output. -func (t *T) Check(function interface{}, description string) { - err := quick.Check(function, nil) - if err == nil { - t.Ok(true, description) - return - } - - t.Diagnostic(err.Error()) - t.Ok(false, description) -} - -// Count returns the number of tests completed so far. -func (t *T) Count() int { - return *t.nextTestNumber - 1 -} - -// AutoPlan generates a test plan based on the number of tests that were run. -func (t *T) AutoPlan() { - t.printf("1..%d\n", t.Count()) -} - -func escapeNewlines(s string) string { - return strings.Replace(strings.TrimRight(s, "\n"), "\n", "\n# ", -1) -} - -// Todo returns copy of the test-state with TODO set. -func (t *T) Todo() *T { - newT := *t - newT.TODO = true - return &newT -} - -// Skip indicates that a test has been skipped. -func (t *T) Skip(count int, description string) { - for i := 0; i < count; i++ { - t.printf("ok %d # SKIP %s\n", *t.nextTestNumber, description) - (*t.nextTestNumber)++ - } -} - -// Diagnostic generates a diagnostic from the message, -// which may span multiple lines. -func (t *T) Diagnostic(message string) { - t.printf("# %s\n", escapeNewlines(message)) -} - -// Diagnosticf generates a diagnostic from the format string and arguments, -// which may span multiple lines. -func (t *T) Diagnosticf(format string, a ...interface{}) { - t.printf("# "+escapeNewlines(format)+"\n", a...) -} - -// YAML generates a YAML block from the message. -func (t *T) YAML(message interface{}) error { - bytes, err := yaml(message, " ") - if err != nil { - return err - } - t.printf(" ---\n ") - t.printf(string(bytes)) - t.printf(" ...\n") - return nil -} diff --git a/vendor/github.com/mndrix/tap-go/yaml_json.go b/vendor/github.com/mndrix/tap-go/yaml_json.go deleted file mode 100644 index f848e642..00000000 --- a/vendor/github.com/mndrix/tap-go/yaml_json.go +++ /dev/null @@ -1,22 +0,0 @@ -// +build !yaml - -package tap - -import ( - "encoding/json" -) - -// yaml serializes a message to YAML. This implementation uses JSON, -// which is a subset of YAML [1] and is implemented by Go's standard -// library. -// -// [1]: http://www.yaml.org/spec/1.2/spec.html#id2759572 -func yaml(message interface{}, prefix string) (marshaled []byte, err error) { - marshaled, err = json.MarshalIndent(message, prefix, " ") - if err != nil { - return marshaled, err - } - - marshaled = append(marshaled, []byte("\n")...) - return marshaled, err -} diff --git a/vendor/github.com/mndrix/tap-go/yaml_yaml.go b/vendor/github.com/mndrix/tap-go/yaml_yaml.go deleted file mode 100644 index 93c6f2e8..00000000 --- a/vendor/github.com/mndrix/tap-go/yaml_yaml.go +++ /dev/null @@ -1,23 +0,0 @@ -// +build yaml - -package tap - -import ( - "bytes" - - goyaml "gopkg.in/yaml.v2" -) - -// yaml serializes a message to YAML. This implementation uses -// non-JSON YAML, which has better prove support [1]. -// -// [1]: https://rt.cpan.org/Public/Bug/Display.html?id=121606 -func yaml(message interface{}, prefix string) (marshaled []byte, err error) { - marshaled, err = goyaml.Marshal(message) - if err != nil { - return marshaled, err - } - - marshaled = bytes.Replace(marshaled, []byte("\n"), []byte("\n"+prefix), -1) - return marshaled[:len(marshaled)-len(prefix)], err -} diff --git a/vendor/modules.txt b/vendor/modules.txt index e367ed9f..ba291c45 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -13,9 +13,6 @@ github.com/hashicorp/errwrap # github.com/hashicorp/go-multierror v1.1.1 ## explicit; go 1.13 github.com/hashicorp/go-multierror -# github.com/mndrix/tap-go v0.0.0-20171203230836-629fa407e90b -## explicit -github.com/mndrix/tap-go # github.com/mrunalp/fileutils v0.5.0 ## explicit; go 1.13 github.com/mrunalp/fileutils