Skip to content

Commit dbc6b50

Browse files
authored
vlib: make ./v -Wimpure-v -W test vlib/ pass on Linux (#21554)
1 parent 373b91c commit dbc6b50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+11278
-222
lines changed
File renamed without changes.

vlib/crypto/sha256/sha256_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ fn test_crypto_sha256_224() {
4646
// with checksum
4747
digest.reset()
4848
_ := digest.write(data)!
49-
chksum := digest.checksum()
49+
chksum := digest.sum([])
5050
assert chksum.hex() == expected
5151
}

vlib/crypto/sha512/sha512_test.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn test_crypto_sha512_384() {
4545

4646
d.reset()
4747
d.write(data) or { assert false }
48-
chksum := d.checksum()
48+
chksum := d.sum([])
4949
assert chksum.hex() == expected
5050
}
5151

@@ -62,7 +62,7 @@ fn test_crypto_sha512_224() {
6262

6363
d.reset()
6464
d.write(data) or { assert false }
65-
chksum := d.checksum()
65+
chksum := d.sum([])
6666
assert chksum.hex() == expected
6767
}
6868

@@ -79,6 +79,6 @@ fn test_crypto_sha512_256() {
7979

8080
d.reset()
8181
d.write(data) or { assert false }
82-
chksum := d.checksum()
82+
chksum := d.sum([])
8383
assert chksum.hex() == expected
8484
}

vlib/db/mysql/mysql_orm_test.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ struct TestDefaultAttribute {
3636
}
3737

3838
fn test_mysql_orm() {
39+
$if !network ? {
40+
eprintln('> Skipping test ${@FN}, since `-d network` is not passed.')
41+
eprintln('> This test requires a working mysql server running on localhost.')
42+
return
43+
}
3944
mut db := mysql.connect(
4045
host: '127.0.0.1'
4146
port: 3306

vlib/db/mysql/mysql_test.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import db.mysql
22

33
fn test_mysql() {
4+
$if !network ? {
5+
eprintln('> Skipping test ${@FN}, since `-d network` is not passed.')
6+
eprintln('> This test requires a working mysql server running on localhost.')
7+
return
8+
}
49
config := mysql.Config{
510
host: '127.0.0.1'
611
port: 3306

vlib/db/mysql/prepared_stmt_test.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import db.mysql
22

33
fn test_prep() {
4+
$if !network ? {
5+
eprintln('> Skipping test ${@FN}, since `-d network` is not passed.')
6+
eprintln('> This test requires a working mysql server running on localhost.')
7+
return
8+
}
49
config := mysql.Config{
510
host: '127.0.0.1'
611
port: 3306

vlib/db/pg/pg_double_test.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ struct Demo {
1010
}
1111

1212
fn test_float_field() {
13+
$if !network ? {
14+
eprintln('> Skipping test ${@FN}, since `-d network` is not passed.')
15+
eprintln('> This test requires a working postgres server running on localhost.')
16+
return
17+
}
1318
conn := 'host=localhost user=test password=test' // insert own connection string
1419
db := pg.connect_with_conninfo(conn)!
1520
defer {

vlib/db/pg/pg_orm_test.v

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ struct TestDefaultAttribute {
3636
}
3737

3838
fn test_pg_orm() {
39+
$if !network ? {
40+
eprintln('> Skipping test ${@FN}, since `-d network` is not passed.')
41+
eprintln('> This test requires a working postgres server running on localhost.')
42+
return
43+
}
3944
mut db := pg.connect(
4045
host: 'localhost'
4146
user: 'postgres'
@@ -51,7 +56,7 @@ fn test_pg_orm() {
5156
orm.TableField{
5257
name: 'id'
5358
typ: typeof[string]().idx
54-
is_time: false
59+
// is_time: false
5560
default_val: ''
5661
is_arr: false
5762
attrs: [
@@ -72,15 +77,15 @@ fn test_pg_orm() {
7277
orm.TableField{
7378
name: 'name'
7479
typ: typeof[string]().idx
75-
is_time: false
80+
// is_time: false
7681
default_val: ''
7782
is_arr: false
7883
attrs: []
7984
},
8085
orm.TableField{
8186
name: 'age'
8287
typ: typeof[i64]().idx
83-
is_time: false
88+
// is_time: false
8489
default_val: ''
8590
is_arr: false
8691
attrs: []
@@ -152,7 +157,8 @@ fn test_pg_orm() {
152157
information_schema_custom_sql := ['integer', 'text', 'character varying',
153158
'timestamp without time zone', 'uuid']
154159
for data_type in result_custom_sql {
155-
information_schema_data_types_results << data_type.vals[0]
160+
x := data_type.vals[0]!
161+
information_schema_data_types_results << x?
156162
}
157163

158164
sql db {
@@ -217,7 +223,8 @@ fn test_pg_orm() {
217223
mut information_schema_defaults_results := []string{}
218224

219225
for defaults in result_defaults {
220-
information_schema_defaults_results << defaults.vals[0]
226+
x := defaults.vals[0]!
227+
information_schema_defaults_results << x?
221228
}
222229
sql db {
223230
drop table TestDefaultAttribute

vlib/db/pg/pg_test.v

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@ module main
22

33
import db.pg
44

5-
const query = 'SELECT ischema.table_schema, c.relname, a.attname, t.typname, t.typalign, t.typlen
6-
FROM pg_class c
7-
JOIN information_schema.tables ischema on ischema.table_name = c.relname
8-
JOIN pg_attribute a ON (a.attrelid = c.oid)
9-
JOIN pg_type t ON (t.oid = a.atttypid)
10-
WHERE
11-
a.attnum >= 0'
12-
135
fn test_large_exec() {
6+
$if !network ? {
7+
eprintln('> Skipping test ${@FN}, since `-d network` is not passed.')
8+
eprintln('> This test requires a working postgres server running on localhost.')
9+
return
10+
}
11+
1412
db := pg.connect(pg.Config{ user: 'postgres', password: 'secret', dbname: 'postgres' })!
1513
defer {
1614
db.close()
1715
}
1816

19-
rows := db.exec(query)!
17+
rows := db.exec('
18+
SELECT ischema.table_schema, c.relname, a.attname, t.typname, t.typalign, t.typlen
19+
FROM pg_class c
20+
JOIN information_schema.tables ischema on ischema.table_name = c.relname
21+
JOIN pg_attribute a ON (a.attrelid = c.oid)
22+
JOIN pg_type t ON (t.oid = a.atttypid)
23+
WHERE
24+
a.attnum >= 0
25+
')!
2026
for row in rows {
2127
// We just need to access the memory to ensure it's properly allocated
2228
row.str()

vlib/net/http/server_test.v

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ fn (mut handler MyHttpHandler) handle(req http.Request) http.Response {
112112
return r
113113
}
114114

115-
const cport = 18197
116-
117115
fn test_server_custom_handler() {
118116
log.warn('${@FN} started')
119117
defer {
@@ -123,7 +121,7 @@ fn test_server_custom_handler() {
123121
mut server := &http.Server{
124122
accept_timeout: atimeout
125123
handler: handler
126-
port: cport
124+
addr: ':18197'
127125
}
128126
t := spawn server.listen_and_serve()
129127
server.wait_till_running()!

0 commit comments

Comments
 (0)