From 9859b3e886c8d551062cd2a824f09ff63196d9d5 Mon Sep 17 00:00:00 2001 From: Robert Iannucci Date: Wed, 27 Oct 2021 22:30:55 -0700 Subject: [PATCH] Automatically generate assertions.go Adds a scrappy script to update assertions.go directly from the assertions library's own exported Should* symbols. --- convey/assertions.go | 124 ++++++++++++++++++------------------ convey/update_assertions.sh | 31 +++++++++ 2 files changed, 94 insertions(+), 61 deletions(-) create mode 100755 convey/update_assertions.sh diff --git a/convey/assertions.go b/convey/assertions.go index 9fad7c29..bff8eacc 100644 --- a/convey/assertions.go +++ b/convey/assertions.go @@ -1,73 +1,75 @@ package convey +// DO NOT EDIT: generated by update_assertions.sh + +//go:generate ./update_assertions.sh + import "github.com/smartystreets/assertions" +// These assertions are forwarded from github.com/smartystreets/assertions +// in order to make convey self-contained. var ( - ShouldEqual = assertions.ShouldEqual - ShouldNotEqual = assertions.ShouldNotEqual - ShouldAlmostEqual = assertions.ShouldAlmostEqual - ShouldNotAlmostEqual = assertions.ShouldNotAlmostEqual - ShouldEqualJSON = assertions.ShouldEqualJSON - ShouldResemble = assertions.ShouldResemble - ShouldNotResemble = assertions.ShouldNotResemble - ShouldPointTo = assertions.ShouldPointTo - ShouldNotPointTo = assertions.ShouldNotPointTo - ShouldBeNil = assertions.ShouldBeNil - ShouldNotBeNil = assertions.ShouldNotBeNil - ShouldBeTrue = assertions.ShouldBeTrue - ShouldBeFalse = assertions.ShouldBeFalse - ShouldBeZeroValue = assertions.ShouldBeZeroValue - ShouldNotBeZeroValue = assertions.ShouldNotBeZeroValue - + ShouldAlmostEqual = assertions.ShouldAlmostEqual + ShouldBeBetween = assertions.ShouldBeBetween + ShouldBeBetweenOrEqual = assertions.ShouldBeBetweenOrEqual + ShouldBeBlank = assertions.ShouldBeBlank + ShouldBeChronological = assertions.ShouldBeChronological + ShouldBeEmpty = assertions.ShouldBeEmpty + ShouldBeError = assertions.ShouldBeError + ShouldBeFalse = assertions.ShouldBeFalse ShouldBeGreaterThan = assertions.ShouldBeGreaterThan ShouldBeGreaterThanOrEqualTo = assertions.ShouldBeGreaterThanOrEqualTo + ShouldBeIn = assertions.ShouldBeIn ShouldBeLessThan = assertions.ShouldBeLessThan ShouldBeLessThanOrEqualTo = assertions.ShouldBeLessThanOrEqualTo - ShouldBeBetween = assertions.ShouldBeBetween + ShouldBeNil = assertions.ShouldBeNil + ShouldBeTrue = assertions.ShouldBeTrue + ShouldBeZeroValue = assertions.ShouldBeZeroValue + ShouldContain = assertions.ShouldContain + ShouldContainKey = assertions.ShouldContainKey + ShouldContainSubstring = assertions.ShouldContainSubstring + ShouldEndWith = assertions.ShouldEndWith + ShouldEqual = assertions.ShouldEqual + ShouldEqualJSON = assertions.ShouldEqualJSON + ShouldEqualTrimSpace = assertions.ShouldEqualTrimSpace + ShouldEqualWithout = assertions.ShouldEqualWithout + ShouldHappenAfter = assertions.ShouldHappenAfter + ShouldHappenBefore = assertions.ShouldHappenBefore + ShouldHappenBetween = assertions.ShouldHappenBetween + ShouldHappenOnOrAfter = assertions.ShouldHappenOnOrAfter + ShouldHappenOnOrBefore = assertions.ShouldHappenOnOrBefore + ShouldHappenOnOrBetween = assertions.ShouldHappenOnOrBetween + ShouldHappenWithin = assertions.ShouldHappenWithin + ShouldHaveLength = assertions.ShouldHaveLength + ShouldHaveSameTypeAs = assertions.ShouldHaveSameTypeAs + ShouldImplement = assertions.ShouldImplement + ShouldNotAlmostEqual = assertions.ShouldNotAlmostEqual ShouldNotBeBetween = assertions.ShouldNotBeBetween - ShouldBeBetweenOrEqual = assertions.ShouldBeBetweenOrEqual ShouldNotBeBetweenOrEqual = assertions.ShouldNotBeBetweenOrEqual - - ShouldContain = assertions.ShouldContain - ShouldNotContain = assertions.ShouldNotContain - ShouldContainKey = assertions.ShouldContainKey - ShouldNotContainKey = assertions.ShouldNotContainKey - ShouldBeIn = assertions.ShouldBeIn - ShouldNotBeIn = assertions.ShouldNotBeIn - ShouldBeEmpty = assertions.ShouldBeEmpty - ShouldNotBeEmpty = assertions.ShouldNotBeEmpty - ShouldHaveLength = assertions.ShouldHaveLength - - ShouldStartWith = assertions.ShouldStartWith - ShouldNotStartWith = assertions.ShouldNotStartWith - ShouldEndWith = assertions.ShouldEndWith - ShouldNotEndWith = assertions.ShouldNotEndWith - ShouldBeBlank = assertions.ShouldBeBlank - ShouldNotBeBlank = assertions.ShouldNotBeBlank - ShouldContainSubstring = assertions.ShouldContainSubstring - ShouldNotContainSubstring = assertions.ShouldNotContainSubstring - - ShouldPanic = assertions.ShouldPanic - ShouldNotPanic = assertions.ShouldNotPanic - ShouldPanicWith = assertions.ShouldPanicWith - ShouldNotPanicWith = assertions.ShouldNotPanicWith - - ShouldHaveSameTypeAs = assertions.ShouldHaveSameTypeAs - ShouldNotHaveSameTypeAs = assertions.ShouldNotHaveSameTypeAs - ShouldImplement = assertions.ShouldImplement - ShouldNotImplement = assertions.ShouldNotImplement - - ShouldHappenBefore = assertions.ShouldHappenBefore - ShouldHappenOnOrBefore = assertions.ShouldHappenOnOrBefore - ShouldHappenAfter = assertions.ShouldHappenAfter - ShouldHappenOnOrAfter = assertions.ShouldHappenOnOrAfter - ShouldHappenBetween = assertions.ShouldHappenBetween - ShouldHappenOnOrBetween = assertions.ShouldHappenOnOrBetween - ShouldNotHappenOnOrBetween = assertions.ShouldNotHappenOnOrBetween - ShouldHappenWithin = assertions.ShouldHappenWithin - ShouldNotHappenWithin = assertions.ShouldNotHappenWithin - ShouldBeChronological = assertions.ShouldBeChronological - - ShouldBeError = assertions.ShouldBeError - ShouldWrap = assertions.ShouldWrap + ShouldNotBeBlank = assertions.ShouldNotBeBlank + ShouldNotBeChronological = assertions.ShouldNotBeChronological + ShouldNotBeEmpty = assertions.ShouldNotBeEmpty + ShouldNotBeIn = assertions.ShouldNotBeIn + ShouldNotBeNil = assertions.ShouldNotBeNil + ShouldNotBeZeroValue = assertions.ShouldNotBeZeroValue + ShouldNotContain = assertions.ShouldNotContain + ShouldNotContainKey = assertions.ShouldNotContainKey + ShouldNotContainSubstring = assertions.ShouldNotContainSubstring + ShouldNotEndWith = assertions.ShouldNotEndWith + ShouldNotEqual = assertions.ShouldNotEqual + ShouldNotHappenOnOrBetween = assertions.ShouldNotHappenOnOrBetween + ShouldNotHappenWithin = assertions.ShouldNotHappenWithin + ShouldNotHaveSameTypeAs = assertions.ShouldNotHaveSameTypeAs + ShouldNotImplement = assertions.ShouldNotImplement + ShouldNotPanic = assertions.ShouldNotPanic + ShouldNotPanicWith = assertions.ShouldNotPanicWith + ShouldNotPointTo = assertions.ShouldNotPointTo + ShouldNotResemble = assertions.ShouldNotResemble + ShouldNotStartWith = assertions.ShouldNotStartWith + ShouldPanic = assertions.ShouldPanic + ShouldPanicWith = assertions.ShouldPanicWith + ShouldPointTo = assertions.ShouldPointTo + ShouldResemble = assertions.ShouldResemble + ShouldStartWith = assertions.ShouldStartWith + ShouldWrap = assertions.ShouldWrap ) diff --git a/convey/update_assertions.sh b/convey/update_assertions.sh new file mode 100755 index 00000000..df280622 --- /dev/null +++ b/convey/update_assertions.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +cd "$(dirname $(realpath $0))" + +ASSERTIONS=($( + go tool nm "$(go list -export -f '{{.Export}}' github.com/smartystreets/assertions)" |\ + awk '/ T github\.com\/smartystreets\/assertions\.Should/{split($3, a, "."); print a[3]}' |\ + sort | uniq)) + +( + echo "package convey" + echo + echo "// DO NOT EDIT: generated by update_assertions.sh" + echo + echo "//go:generate ./update_assertions.sh" + echo + echo "import \"github.com/smartystreets/assertions\"" + echo + echo "// These assertions are forwarded from github.com/smartystreets/assertions" + echo "// in order to make convey self-contained." + echo "var (" + + for assertion in "${ASSERTIONS[@]}" + do + echo " $assertion = assertions.$assertion" + done + + echo ")" +) > ./assertions.go + +go fmt ./assertions.go