@@ -9,16 +9,9 @@ import (
9
9
"testing"
10
10
"time"
11
11
12
- "github.com/bmizerany /assert"
12
+ "github.com/stretchrcom/testify /assert"
13
13
)
14
14
15
- func softAssert (t * testing.T , cond bool , msg string ) {
16
- if ! cond {
17
- print ("assertion fail: " , msg , "\n " )
18
- panic (1 )
19
- }
20
- }
21
-
22
15
func caller () string {
23
16
if _ , _ , line , ok := runtime .Caller (2 ); ok {
24
17
return fmt .Sprintf ("(actual-line %v) " , line )
@@ -79,13 +72,15 @@ func assertMapEqual(t *testing.T, seq1, seq2 interface{}) {
79
72
func assertDiffEqual (t * testing.T , seq1 , seq2 []Diff ) {
80
73
if a , b := len (seq1 ), len (seq2 ); a != b {
81
74
t .Errorf ("%v\n seq1:\n %v\n seq2:\n %v" , caller (), pretty (seq1 ), pretty (seq2 ))
82
- t .Fatalf ("%v Sequences of different length: %v != %v" , caller (), a , b )
75
+ t .Errorf ("%v Sequences of different length: %v != %v" , caller (), a , b )
76
+ return
83
77
}
84
78
85
79
for i := range seq1 {
86
80
if a , b := seq1 [i ], seq2 [i ]; a != b {
87
81
t .Errorf ("%v\n seq1:\n %v\n seq2:\n %v" , caller (), pretty (seq1 ), pretty (seq2 ))
88
- t .Fatalf ("%v %v != %v" , caller (), a , b )
82
+ t .Errorf ("%v %v != %v" , caller (), a , b )
83
+ return
89
84
}
90
85
}
91
86
}
@@ -166,8 +161,8 @@ func Test_diffHalfmatchTest(t *testing.T) {
166
161
dmp := New ()
167
162
dmp .DiffTimeout = 1
168
163
// No match.
169
- softAssert (t , dmp .DiffHalfMatch ("1234567890" , "abcdef" ) == nil , "" )
170
- softAssert (t , dmp .DiffHalfMatch ("12345" , "23" ) == nil , "" )
164
+ assert . True (t , dmp .DiffHalfMatch ("1234567890" , "abcdef" ) == nil , "" )
165
+ assert . True (t , dmp .DiffHalfMatch ("12345" , "23" ) == nil , "" )
171
166
172
167
// Single Match.
173
168
assertStrEqual (t ,
@@ -193,7 +188,7 @@ func Test_diffHalfmatchTest(t *testing.T) {
193
188
194
189
// Optimal no halfmatch.
195
190
dmp .DiffTimeout = 0
196
- softAssert (t , dmp .DiffHalfMatch ("qHilloHelloHew" , "xHelloHeHulloy" ) == nil , "" )
191
+ assert . True (t , dmp .DiffHalfMatch ("qHilloHelloHew" , "xHelloHeHulloy" ) == nil , "" )
197
192
}
198
193
199
194
func Test_diffLinesToChars (t * testing.T ) {
@@ -703,13 +698,13 @@ func Test_diffDelta(t *testing.T) {
703
698
// Generates error (19 < 20).
704
699
_ , err = dmp .DiffFromDelta (text1 + "x" , delta )
705
700
if err == nil {
706
- panic ( 1 ) //assert.Fail ("diff_fromDelta: Too long.");
701
+ t . Fatal ("diff_fromDelta: Too long." )
707
702
}
708
703
709
704
// Generates error (19 > 18).
710
705
_ , err = dmp .DiffFromDelta (text1 [1 :], delta )
711
706
if err == nil {
712
- panic ( 1 ) //assert.Fail ("diff_fromDelta: Too short.");
707
+ t . Fatal ("diff_fromDelta: Too short." )
713
708
}
714
709
715
710
// Generates error (%c3%xy invalid Unicode).
@@ -880,7 +875,12 @@ func Test_diffMain(t *testing.T) {
880
875
Diff {DiffDelete , "EFGHIJKLMNOefg" }}
881
876
assertDiffEqual (t , diffs , dmp .DiffMain ("ABCDa=bcd=efghijklmnopqrsEFGHIJKLMNOefg" , "a-bcd-efghijklmnopqrs" , false ))
882
877
883
- diffs = []Diff {Diff {DiffInsert , " " }, Diff {DiffEqual , "a" }, Diff {DiffInsert , "nd" }, Diff {DiffEqual , " [[Pennsylvania]]" }, Diff {DiffDelete , " and [[New" }}
878
+ diffs = []Diff {
879
+ Diff {DiffInsert , " " },
880
+ Diff {DiffEqual , "a" },
881
+ Diff {DiffInsert , "nd" },
882
+ Diff {DiffEqual , " [[Pennsylvania]]" },
883
+ Diff {DiffDelete , " and [[New" }}
884
884
assertDiffEqual (t , diffs , dmp .DiffMain ("a [[Pennsylvania]] and [[New" , " and [[Pennsylvania]]" , false ))
885
885
886
886
dmp .DiffTimeout = 0.1 // 100ms
@@ -897,11 +897,11 @@ func Test_diffMain(t *testing.T) {
897
897
endTime := time .Now ().Unix ()
898
898
endTime *= 1000
899
899
// Test that we took at least the timeout period.
900
- softAssert (t , dmp .DiffTimeout * 1000 <= float64 (endTime - startTime ), "" )
900
+ assert . True (t , dmp .DiffTimeout * 1000 <= float64 (endTime - startTime ), "" )
901
901
// Test that we didn't take forever (be forgiving).
902
902
// Theoretically this test could fail very occasionally if the
903
903
// OS task swaps or locks up for a second at the wrong moment.
904
- softAssert (t , dmp .DiffTimeout * 1000 * 2 > float64 (endTime - startTime ), "" )
904
+ assert . True (t , dmp .DiffTimeout * 1000 * 2 > float64 (endTime - startTime ), "" )
905
905
dmp .DiffTimeout = 0
906
906
907
907
// Test the linemode speedup.
@@ -1034,7 +1034,7 @@ func Test_patch_fromText(t *testing.T) {
1034
1034
dmp := New ()
1035
1035
1036
1036
_v1 , _ := dmp .PatchFromText ("" )
1037
- softAssert (t , len (_v1 ) == 0 , "patch_fromText: #0." )
1037
+ assert . True (t , len (_v1 ) == 0 , "patch_fromText: #0." )
1038
1038
strp := "@@ -21,18 +22,17 @@\n jump\n -s\n +ed\n over \n -the\n +a\n %0Alaz\n "
1039
1039
_v2 , _ := dmp .PatchFromText (strp )
1040
1040
assert .Equal (t , strp , _v2 [0 ].String (), "patch_fromText: #1." )
@@ -1050,7 +1050,7 @@ func Test_patch_fromText(t *testing.T) {
1050
1050
1051
1051
// Generates error.
1052
1052
_ , err := dmp .PatchFromText ("Bad\n Patch\n " )
1053
- softAssert (t , err != nil , "There should be an error" )
1053
+ assert . True (t , err != nil , "There should be an error" )
1054
1054
}
1055
1055
1056
1056
func Test_patch_toText (t * testing.T ) {
@@ -1172,9 +1172,13 @@ func Test_PatchAddPadding(t *testing.T) {
1172
1172
dmp := New ()
1173
1173
var patches []Patch
1174
1174
patches = dmp .PatchMake ("" , "test" )
1175
- assert .Equal (t , "@@ -0,0 +1,4 @@\n +test\n " ,
1175
+ pass := assert .Equal (t , "@@ -0,0 +1,4 @@\n +test\n " ,
1176
1176
dmp .PatchToText (patches ),
1177
1177
"PatchAddPadding: Both edges full." )
1178
+ if ! pass {
1179
+ t .FailNow ()
1180
+ }
1181
+
1178
1182
dmp .PatchAddPadding (patches )
1179
1183
assert .Equal (t , "@@ -1,8 +1,12 @@\n %01%02%03%04\n +test\n %01%02%03%04\n " ,
1180
1184
dmp .PatchToText (patches ),
@@ -1209,7 +1213,10 @@ func Test_patchApply(t *testing.T) {
1209
1213
results0 , results1 := dmp .PatchApply (patches , "Hello world." )
1210
1214
boolArray := results1
1211
1215
resultStr := results0 + "\t " + string (len (boolArray ))
1212
- assert .Equal (t , "Hello world.\t 0" , resultStr , "patch_apply: Null case." )
1216
+ pass := assert .Equal (t , "Hello world.\t 0" , resultStr , "patch_apply: Null case." )
1217
+ if ! pass {
1218
+ t .FailNow ()
1219
+ }
1213
1220
1214
1221
patches = dmp .PatchMake ("The quick brown fox jumps over the lazy dog." , "That quick brown fox jumped over a lazy dog." )
1215
1222
results0 , results1 = dmp .PatchApply (patches , "The quick brown fox jumps over the lazy dog." )
0 commit comments