1414 limitations under the License.
1515*/
1616
17+ //revive:disable:package-comments // annoying false positive behavior
18+ //nolint:thelper // FIXME: remove when we move to tig.T
1719package expect
1820
1921import (
20- "encoding/hex"
21- "fmt"
2222 "regexp"
23- "strings"
2423 "testing"
2524
2625 "github.com/containerd/nerdctl/mod/tigron/internal/assertive"
@@ -29,7 +28,6 @@ import (
2928
3029// All can be used as a parameter for expected.Output to group a set of comparators.
3130func All (comparators ... test.Comparator ) test.Comparator {
32- //nolint:thelper
3331 return func (stdout , info string , t * testing.T ) {
3432 t .Helper ()
3533
@@ -39,57 +37,35 @@ func All(comparators ...test.Comparator) test.Comparator {
3937 }
4038}
4139
42- // Contains can be used as a parameter for expected.Output and ensures a comparison string
43- // is found contained in the output.
40+ // Contains can be used as a parameter for expected.Output and ensures a comparison string is found contained in the
41+ // output.
4442func Contains (compare string ) test.Comparator {
45- //nolint:thelper
4643 return func (stdout , info string , t * testing.T ) {
4744 t .Helper ()
48- assertive .Check (t , strings .Contains (stdout , compare ),
49- fmt .Sprintf ("Output does not contain: %q" , compare ),
50- info )
45+ assertive .Contains (assertive .WithFailLater (t ), stdout , compare , info )
5146 }
5247}
5348
54- // DoesNotContain is to be used for expected.Output to ensure a comparison string is NOT found in
55- // the output.
49+ // DoesNotContain is to be used for expected.Output to ensure a comparison string is NOT found in the output.
5650func DoesNotContain (compare string ) test.Comparator {
57- //nolint:thelper
5851 return func (stdout , info string , t * testing.T ) {
5952 t .Helper ()
60- assertive .Check (t , ! strings .Contains (stdout , compare ),
61- fmt .Sprintf ("Output should not contain: %q" , compare ), info )
53+ assertive .DoesNotContain (assertive .WithFailLater (t ), stdout , compare , info )
6254 }
6355}
6456
6557// Equals is to be used for expected.Output to ensure it is exactly the output.
6658func Equals (compare string ) test.Comparator {
67- //nolint:thelper
6859 return func (stdout , info string , t * testing.T ) {
6960 t .Helper ()
70-
71- hexdump := hex .Dump ([]byte (stdout ))
72- assertive .Check (
73- t ,
74- compare == stdout ,
75- fmt .Sprintf ("Output is not equal to: %q" , compare ),
76- "\n " + hexdump ,
77- info ,
78- )
61+ assertive .IsEqual (assertive .WithFailLater (t ), stdout , compare , info )
7962 }
8063}
8164
8265// Match is to be used for expected.Output to ensure we match a regexp.
83- // Provisional - expected use, but have not seen it so far.
8466func Match (reg * regexp.Regexp ) test.Comparator {
85- //nolint:thelper
8667 return func (stdout , info string , t * testing.T ) {
8768 t .Helper ()
88- assertive .Check (
89- t ,
90- reg .MatchString (stdout ),
91- fmt .Sprintf ("Output does not match: %q" , reg .String ()),
92- info ,
93- )
69+ assertive .Match (assertive .WithFailLater (t ), stdout , reg , info )
9470 }
9571}
0 commit comments