Skip to content

Commit 9719d4b

Browse files
committed
Better tests.
1 parent b21c69d commit 9719d4b

File tree

14 files changed

+220
-177
lines changed

14 files changed

+220
-177
lines changed

ext/blobio/blob_test.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,16 @@ func Test_readblob(t *testing.T) {
144144
}
145145
}
146146

147-
if stmt.Step() {
148-
got := stmt.ColumnText(0)
149-
if got != tt.want1 {
150-
t.Errorf("got %q", got)
151-
}
147+
if !stmt.Step() {
148+
t.Fatal(stmt.Err())
149+
} else if got := stmt.ColumnText(0); got != tt.want1 {
150+
t.Errorf("got %q", got)
152151
}
153152

154-
if stmt.Step() {
155-
got := stmt.ColumnText(0)
156-
if got != tt.want2 {
157-
t.Errorf("got %q", got)
158-
}
153+
if !stmt.Step() {
154+
t.Fatal(stmt.Err())
155+
} else if got := stmt.ColumnText(0); got != tt.want2 {
156+
t.Errorf("got %q", got)
159157
}
160158

161159
err = stmt.Err()

ext/csv/csv_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,21 @@ func TestAffinity(t *testing.T) {
147147
}
148148
defer stmt.Close()
149149

150-
if stmt.Step() {
151-
if got := stmt.ColumnText(0); got != "1" {
152-
t.Errorf("got %q want 1", got)
153-
}
150+
if !stmt.Step() {
151+
t.Fatal(stmt.Err())
152+
} else if got := stmt.ColumnText(0); got != "1" {
153+
t.Errorf("got %q want 1", got)
154154
}
155-
if stmt.Step() {
156-
if got := stmt.ColumnText(0); got != "0.1" {
157-
t.Errorf("got %q want 0.1", got)
158-
}
155+
if !stmt.Step() {
156+
t.Fatal(stmt.Err())
157+
} else if got := stmt.ColumnText(0); got != "0.1" {
158+
t.Errorf("got %q want 0.1", got)
159159
}
160-
if stmt.Step() {
161-
if got := stmt.ColumnText(0); got != "e" {
162-
t.Errorf("got %q want e", got)
163-
}
160+
161+
if !stmt.Step() {
162+
t.Fatal(stmt.Err())
163+
} else if got := stmt.ColumnText(0); got != "e" {
164+
t.Errorf("got %q want e", got)
164165
}
165166
}
166167

ext/pivot/pivot_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ func TestRegister(t *testing.T) {
141141
}
142142
defer stmt.Close()
143143

144-
if stmt.Step() {
145-
if got := stmt.ColumnInt(0); got != 3 {
146-
t.Errorf("got %d, want 3", got)
147-
}
144+
if !stmt.Step() {
145+
t.Fatal(stmt.Err())
146+
} else if got := stmt.ColumnInt(0); got != 3 {
147+
t.Errorf("got %d, want 3", got)
148148
}
149149

150150
err = db.Exec(`ALTER TABLE v_x RENAME TO v_y`)

ext/statement/stmt_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ func TestRegister(t *testing.T) {
9292
}
9393
defer stmt.Close()
9494

95-
if stmt.Step() {
95+
if !stmt.Step() {
96+
t.Fatal(stmt.Err())
97+
} else {
9698
x := stmt.ColumnInt(0)
9799
y := stmt.ColumnInt(1)
98100
hypot := stmt.ColumnInt(2)

ext/stats/boolean_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ func TestRegister_boolean(t *testing.T) {
3737
if err != nil {
3838
t.Fatal(err)
3939
}
40-
if stmt.Step() {
40+
if !stmt.Step() {
41+
t.Fatal(stmt.Err())
42+
} else {
4143
if got := stmt.ColumnBool(0); got != true {
4244
t.Errorf("got %v, want true", got)
4345
}

ext/stats/mode_test.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,54 +21,55 @@ func TestRegister_mode(t *testing.T) {
2121
if err != nil {
2222
t.Fatal(err)
2323
}
24-
if stmt.Step() {
25-
if got := stmt.ColumnInt(0); got != 3 {
26-
t.Errorf("got %v, want 3", got)
27-
}
24+
if !stmt.Step() {
25+
t.Fatal(stmt.Err())
26+
} else if got := stmt.ColumnInt(0); got != 3 {
27+
t.Errorf("got %v, want 3", got)
2828
}
2929
stmt.Close()
3030

3131
stmt, _, err = db.Prepare(`SELECT mode(column1) FROM (VALUES (1), (1), (2), (2), (3))`)
3232
if err != nil {
3333
t.Fatal(err)
3434
}
35-
if stmt.Step() {
36-
if got := stmt.ColumnInt(0); got != 1 {
37-
t.Errorf("got %v, want 1", got)
38-
}
35+
if !stmt.Step() {
36+
t.Fatal(stmt.Err())
37+
} else if got := stmt.ColumnInt(0); got != 1 {
38+
t.Errorf("got %v, want 1", got)
3939
}
4040
stmt.Close()
4141

4242
stmt, _, err = db.Prepare(`SELECT mode(column1) FROM (VALUES (0.5), (1), (2.5), (2), (2.5))`)
4343
if err != nil {
4444
t.Fatal(err)
4545
}
46-
if stmt.Step() {
47-
if got := stmt.ColumnFloat(0); got != 2.5 {
48-
t.Errorf("got %v, want 2.5", got)
49-
}
46+
if !stmt.Step() {
47+
t.Fatal(stmt.Err())
48+
} else if got := stmt.ColumnFloat(0); got != 2.5 {
49+
t.Errorf("got %v, want 2.5", got)
5050
}
5151
stmt.Close()
5252

5353
stmt, _, err = db.Prepare(`SELECT mode(column1) FROM (VALUES ('red'), ('green'), ('blue'), ('red'))`)
5454
if err != nil {
5555
t.Fatal(err)
5656
}
57-
if stmt.Step() {
58-
if got := stmt.ColumnText(0); got != "red" {
59-
t.Errorf("got %q, want red", got)
60-
}
57+
if !stmt.Step() {
58+
t.Fatal(stmt.Err())
59+
} else if got := stmt.ColumnText(0); got != "red" {
60+
t.Errorf("got %q, want red", got)
6161
}
62+
6263
stmt.Close()
6364

6465
stmt, _, err = db.Prepare(`SELECT mode(column1) FROM (VALUES (X'cafebabe'), ('green'), ('blue'), (X'cafebabe'))`)
6566
if err != nil {
6667
t.Fatal(err)
6768
}
68-
if stmt.Step() {
69-
if got := stmt.ColumnText(0); got != "\xca\xfe\xba\xbe" {
70-
t.Errorf("got %q, want cafebabe", got)
71-
}
69+
if !stmt.Step() {
70+
t.Fatal(stmt.Err())
71+
} else if got := stmt.ColumnText(0); got != "\xca\xfe\xba\xbe" {
72+
t.Errorf("got %q, want cafebabe", got)
7273
}
7374
stmt.Close()
7475

@@ -92,10 +93,10 @@ func TestRegister_mode(t *testing.T) {
9293
stmt.BindInt(3, 2)
9394
stmt.BindFloat(4, 2)
9495
stmt.BindFloat(5, 2)
95-
if stmt.Step() {
96-
if got := stmt.ColumnInt(0); got != 2 {
97-
t.Errorf("got %v, want 2", got)
98-
}
96+
if !stmt.Step() {
97+
t.Fatal(stmt.Err())
98+
} else if got := stmt.ColumnInt(0); got != 2 {
99+
t.Errorf("got %v, want 2", got)
99100
}
100101
stmt.Close()
101102
}

ext/stats/percentile_test.go

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ func TestRegister_percentile(t *testing.T) {
3838
if err != nil {
3939
t.Fatal(err)
4040
}
41-
if stmt.Step() {
41+
if !stmt.Step() {
42+
t.Fatal(stmt.Err())
43+
} else {
4244
if got := stmt.ColumnFloat(0); got != 10 {
4345
t.Errorf("got %v, want 10", got)
4446
}
@@ -65,30 +67,30 @@ func TestRegister_percentile(t *testing.T) {
6567
if err != nil {
6668
t.Fatal(err)
6769
}
68-
if stmt.Step() {
69-
if got := stmt.ColumnFloat(0); got != 5.5 {
70-
t.Errorf("got %v, want 5.5", got)
71-
}
70+
if !stmt.Step() {
71+
t.Fatal(stmt.Err())
72+
} else if got := stmt.ColumnFloat(0); got != 5.5 {
73+
t.Errorf("got %v, want 5.5", got)
7274
}
73-
if stmt.Step() {
74-
if got := stmt.ColumnFloat(0); got != 7 {
75-
t.Errorf("got %v, want 7", got)
76-
}
75+
if !stmt.Step() {
76+
t.Fatal(stmt.Err())
77+
} else if got := stmt.ColumnFloat(0); got != 7 {
78+
t.Errorf("got %v, want 7", got)
7779
}
78-
if stmt.Step() {
79-
if got := stmt.ColumnFloat(0); got != 10 {
80-
t.Errorf("got %v, want 10", got)
81-
}
80+
if !stmt.Step() {
81+
t.Fatal(stmt.Err())
82+
} else if got := stmt.ColumnFloat(0); got != 10 {
83+
t.Errorf("got %v, want 10", got)
8284
}
83-
if stmt.Step() {
84-
if got := stmt.ColumnFloat(0); got != 14.5 {
85-
t.Errorf("got %v, want 14.5", got)
86-
}
85+
if !stmt.Step() {
86+
t.Fatal(stmt.Err())
87+
} else if got := stmt.ColumnFloat(0); got != 14.5 {
88+
t.Errorf("got %v, want 14.5", got)
8789
}
88-
if stmt.Step() {
89-
if got := stmt.ColumnFloat(0); got != 16 {
90-
t.Errorf("got %v, want 16", got)
91-
}
90+
if !stmt.Step() {
91+
t.Fatal(stmt.Err())
92+
} else if got := stmt.ColumnFloat(0); got != 16 {
93+
t.Errorf("got %v, want 16", got)
9294
}
9395
stmt.Close()
9496

@@ -103,7 +105,9 @@ func TestRegister_percentile(t *testing.T) {
103105
if err != nil {
104106
t.Fatal(err)
105107
}
106-
if stmt.Step() {
108+
if !stmt.Step() {
109+
t.Fatal(stmt.Err())
110+
} else {
107111
if got := stmt.ColumnFloat(0); got != 4 {
108112
t.Errorf("got %v, want 4", got)
109113
}
@@ -134,7 +138,9 @@ func TestRegister_percentile(t *testing.T) {
134138
if err != nil {
135139
t.Fatal(err)
136140
}
137-
if stmt.Step() {
141+
if !stmt.Step() {
142+
t.Fatal(stmt.Err())
143+
} else {
138144
if got := stmt.ColumnType(0); got != sqlite3.NULL {
139145
t.Error("want NULL")
140146
}

ext/stats/stats_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ func TestRegister_variance(t *testing.T) {
3434
if err != nil {
3535
t.Fatal(err)
3636
}
37-
if stmt.Step() {
38-
if got := stmt.ColumnType(0); got != sqlite3.NULL {
39-
t.Errorf("got %v, want NULL", got)
40-
}
37+
if !stmt.Step() {
38+
t.Fatal(stmt.Err())
39+
} else if got := stmt.ColumnType(0); got != sqlite3.NULL {
40+
t.Errorf("got %v, want NULL", got)
4141
}
4242
stmt.Close()
4343

@@ -57,7 +57,9 @@ func TestRegister_variance(t *testing.T) {
5757
if err != nil {
5858
t.Fatal(err)
5959
}
60-
if stmt.Step() {
60+
if !stmt.Step() {
61+
t.Fatal(stmt.Err())
62+
} else {
6163
if got := stmt.ColumnFloat(0); got != 40 {
6264
t.Errorf("got %v, want 40", got)
6365
}
@@ -131,7 +133,9 @@ func TestRegister_covariance(t *testing.T) {
131133
if err != nil {
132134
t.Fatal(err)
133135
}
134-
if stmt.Step() {
136+
if !stmt.Step() {
137+
t.Fatal(stmt.Err())
138+
} else {
135139
if got := stmt.ColumnInt(0); got != 0 {
136140
t.Errorf("got %v, want 0", got)
137141
}
@@ -249,7 +253,9 @@ func Benchmark_average(b *testing.B) {
249253
b.Fatal(err)
250254
}
251255

252-
if stmt.Step() {
256+
if !stmt.Step() {
257+
b.Fatal(stmt.Err())
258+
} else {
253259
want := float64(b.N) / 2
254260
if got := stmt.ColumnFloat(0); got != want {
255261
b.Errorf("got %v, want %v", got, want)
@@ -283,7 +289,9 @@ func Benchmark_variance(b *testing.B) {
283289
b.Fatal(err)
284290
}
285291

286-
if stmt.Step() && b.N > 100 {
292+
if !stmt.Step() {
293+
b.Fatal(stmt.Err())
294+
} else if b.N > 100 {
287295
want := float64(b.N*b.N) / 12
288296
if got := stmt.ColumnFloat(0); want > (got-want)*float64(b.N) {
289297
b.Errorf("got %v, want %v", got, want)

ext/unicode/unicode_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ func TestRegister(t *testing.T) {
2626
}
2727
defer stmt.Close()
2828

29-
if stmt.Step() {
30-
return stmt.ColumnText(0)
29+
if !stmt.Step() {
30+
t.Fatal(stmt.Err())
3131
}
32-
t.Fatal(stmt.Err())
33-
return ""
32+
return stmt.ColumnText(0)
3433
}
3534

3635
Register(db)

tests/endian_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,15 @@ func Test_endianness(t *testing.T) {
5959
}
6060
defer stmt.Close()
6161

62-
if stmt.Step() {
62+
if !stmt.Step() {
63+
t.Fatal(stmt.Err())
64+
} else {
6365
if got := stmt.ColumnInt64(0); got != value {
6466
t.Errorf("got %d, want %d", got, value)
6567
}
6668
if got := stmt.ColumnText(0); got != strconv.FormatInt(value, 10) {
6769
t.Errorf("got %s, want %d", got, value)
6870
}
6971
}
70-
if err != nil {
71-
t.Fatal(err)
72-
}
7372
}
74-
7573
}

0 commit comments

Comments
 (0)