From 0c192cfd64b4552181538cdd7bba850eff02fd52 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 26 Oct 2020 14:41:57 +0200 Subject: [PATCH] tests: fix warnings when doing `./v -W -progress -check-syntax test-fixed` --- vlib/encoding/utf8/encoding_utf8_test.v | 12 +- vlib/sync/channel_close_test.v | 3 +- vlib/sync/channel_polling_test.v | 22 ++-- vlib/time/time_test.v | 60 ++++----- vlib/v/doc/doc_test.v | 1 - vlib/v/tests/fixed_array_init_test.v | 26 ++-- vlib/v/tests/fixed_array_to_string_test.v | 23 ++-- vlib/v/tests/fn_test.v | 2 +- vlib/v/tests/generic_fn_infer_test.v | 2 +- vlib/v/tests/generics_test.v | 2 +- vlib/v/tests/map_and_array_with_fns_test.v | 118 +++++++++--------- vlib/v/tests/modules/amodule/module.v | 6 +- .../tests/project_with_tests_for_main/main.v | 2 +- vlib/v/tests/repeated_multiret_values_test.v | 2 +- .../tests/reusable_mut_multiret_values_test.v | 2 +- vlib/v/tests/semaphore_test.v | 4 +- .../static_arrays_using_const_for_size_test.v | 12 +- 17 files changed, 143 insertions(+), 156 deletions(-) mode change 100755 => 100644 vlib/sync/channel_polling_test.v diff --git a/vlib/encoding/utf8/encoding_utf8_test.v b/vlib/encoding/utf8/encoding_utf8_test.v index d94be6717e..ebea87ca22 100644 --- a/vlib/encoding/utf8/encoding_utf8_test.v +++ b/vlib/encoding/utf8/encoding_utf8_test.v @@ -1,9 +1,9 @@ -import encoding.utf8 { validate_str } +import encoding.utf8 fn test_validate_str() { - assert validate_str('añçá') == true - assert validate_str('\x61\xC3\xB1\xC3\xA7\xC3\xA1') == true - assert validate_str('\xC0\xC1') == false - assert validate_str('\xF5\xFF') == false - assert validate_str('\xE0\xEF') == false + assert utf8.validate_str('añçá') == true + assert utf8.validate_str('\x61\xC3\xB1\xC3\xA7\xC3\xA1') == true + assert utf8.validate_str('\xC0\xC1') == false + assert utf8.validate_str('\xF5\xFF') == false + assert utf8.validate_str('\xE0\xEF') == false } diff --git a/vlib/sync/channel_close_test.v b/vlib/sync/channel_close_test.v index 2bfc2d7d01..c4d45370a3 100644 --- a/vlib/sync/channel_close_test.v +++ b/vlib/sync/channel_close_test.v @@ -1,9 +1,8 @@ import sync -import time fn do_rec(mut ch sync.Channel, mut resch sync.Channel) { mut sum := i64(0) - for { + for { mut a := 0 if !ch.pop(&a) { break diff --git a/vlib/sync/channel_polling_test.v b/vlib/sync/channel_polling_test.v old mode 100755 new mode 100644 index 731e7cdb69..ba8e1d5c03 --- a/vlib/sync/channel_polling_test.v +++ b/vlib/sync/channel_polling_test.v @@ -1,3 +1,4 @@ + // Channel Benchmark // // `nobj` integers are sent thru a channel with queue length`buflen` @@ -5,12 +6,11 @@ // // The receive threads add all received numbers and send them to the // main thread where the total sum is compare to the expected value. - const ( - nsend = 2 - nrec = 2 - buflen = 100 - nobj = 10000 + nsend = 2 + nrec = 2 + buflen = 100 + nobj = 10000 objs_per_thread = 5000 ) @@ -18,16 +18,18 @@ fn do_rec(ch chan int, resch chan i64, n int) { mut sum := i64(0) for _ in 0 .. n { mut r := 0 - for ch.try_pop(r) != .success {} + for ch.try_pop(r) != .success { + } sum += r } println(sum) resch <- sum } -fn do_send(ch chan int, start, end int) { +fn do_send(ch chan int, start int, end int) { for i in start .. end { - for ch.try_push(i) != .success {} + for ch.try_push(i) != .success { + } } } @@ -46,8 +48,10 @@ fn test_channel_polling() { mut sum := i64(0) for _ in 0 .. nrec { sum += <-resch + println('> running sum: $sum') } // use sum formula by Gauß to calculate the expected result - expected_sum := i64(nobj)*(nobj-1)/2 + expected_sum := i64(nobj) * (nobj - 1) / 2 + println('expected sum: $expected_sum | sum: $sum') assert sum == expected_sum } diff --git a/vlib/time/time_test.v b/vlib/time/time_test.v index f9fe6c6c2f..c348ce1c90 100644 --- a/vlib/time/time_test.v +++ b/vlib/time/time_test.v @@ -24,7 +24,7 @@ fn test_is_leap_year() { assert time.is_leap_year(2100) == false } -fn check_days_in_month(month, year, expected int) bool { +fn check_days_in_month(month int, year int, expected int) bool { res := time.days_in_month(month, year) or { return false } @@ -89,18 +89,21 @@ fn test_format_ss() { } fn test_format_ss_milli() { - assert '11.07.1980 21:23:42.123' == time_to_test.get_fmt_str(.dot, .hhmmss24_milli, .ddmmyyyy) + assert '11.07.1980 21:23:42.123' == + time_to_test.get_fmt_str(.dot, .hhmmss24_milli, .ddmmyyyy) assert '1980-07-11 21:23:42.123' == time_to_test.format_ss_milli() } fn test_format_ss_micro() { - assert '11.07.1980 21:23:42.123456' == time_to_test.get_fmt_str(.dot, .hhmmss24_micro, .ddmmyyyy) + assert '11.07.1980 21:23:42.123456' == + time_to_test.get_fmt_str(.dot, .hhmmss24_micro, .ddmmyyyy) assert '1980-07-11 21:23:42.123456' == time_to_test.format_ss_micro() } fn test_smonth() { - month_names := ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', - 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] + month_names := ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', + 'Dec', + ] for i, name in month_names { month_num := i + 1 t := time.Time{ @@ -117,7 +120,7 @@ fn test_smonth() { } fn test_day_of_week() { - for i in 0..7 { + for i in 0 .. 7 { day_of_week := i + 1 // 2 Dec 2019 is Monday t := time.Time{ @@ -164,33 +167,30 @@ fn test_str() { // not optimal test but will find obvious bugs fn test_now() { now := time.now() - // The year the test was built - assert now.year >= 2020 - assert now.month > 0 - assert now.month <= 12 - assert now.minute >= 0 - assert now.minute < 60 - assert now.second >=0 - assert now.second <= 60 // <= 60 cause of leap seconds - assert now.microsecond >= 0 - assert now.microsecond < 1000000 - + assert now.year >= 2020 + assert now.month > 0 + assert now.month <= 12 + assert now.minute >= 0 + assert now.minute < 60 + assert now.second >= 0 + assert now.second <= 60 // <= 60 cause of leap seconds + assert now.microsecond >= 0 + assert now.microsecond < 1000000 } fn test_utc() { now := time.utc() - // The year the test was built - assert now.year >= 2020 - assert now.month > 0 - assert now.month <= 12 - assert now.minute >= 0 - assert now.minute < 60 - assert now.second >=0 - assert now.second <= 60 // <= 60 cause of leap seconds - assert now.microsecond >= 0 - assert now.microsecond < 1000000 + assert now.year >= 2020 + assert now.month > 0 + assert now.month <= 12 + assert now.minute >= 0 + assert now.minute < 60 + assert now.second >= 0 + assert now.second <= 60 // <= 60 cause of leap seconds + assert now.microsecond >= 0 + assert now.microsecond < 1000000 } fn test_unix_time() { @@ -203,10 +203,10 @@ fn test_unix_time() { // utm1 := t1.unix_time_milli() utm2 := t2.unix_time_milli() - assert (utm1 - u64(ut1)*1000) < 1000 - assert (utm2 - u64(ut2)*1000) < 1000 + assert (utm1 - u64(ut1) * 1000) < 1000 + assert (utm2 - u64(ut2) * 1000) < 1000 // - //println('utm1: $utm1 | utm2: $utm2') + // println('utm1: $utm1 | utm2: $utm2') assert utm2 - utm1 > 2 assert utm2 - utm1 < 999 } diff --git a/vlib/v/doc/doc_test.v b/vlib/v/doc/doc_test.v index 6ea3c2eae1..a9c9ab7d28 100644 --- a/vlib/v/doc/doc_test.v +++ b/vlib/v/doc/doc_test.v @@ -1,6 +1,5 @@ // import v.table import v.doc -import v.parser // fn test_generate_with_pos() {} // fn test_generate() {} diff --git a/vlib/v/tests/fixed_array_init_test.v b/vlib/v/tests/fixed_array_init_test.v index 4da5da1ea1..00f63d9627 100644 --- a/vlib/v/tests/fixed_array_init_test.v +++ b/vlib/v/tests/fixed_array_init_test.v @@ -2,55 +2,47 @@ fn test_fixed_array_lit_init() { a1 := ['1', '2', '3']!! assert typeof(a1) == '[3]string' assert '$a1' == "['1', '2', '3']" - a2 := ['a', 'b']!! assert typeof(a2) == '[2]string' assert '$a2' == "['a', 'b']" - c1 := [1, 2, 3]!! assert typeof(c1) == '[3]int' assert '$c1' == '[1, 2, 3]' - c2 := [i16(1), 2, 3]!! assert typeof(c2) == '[3]i16' assert '$c2' == '[1, 2, 3]' - mut c3 := [i64(1), 2, 3]!! assert typeof(c3) == '[3]i64' assert '$c3' == '[1, 2, 3]' - mut c4 := [u64(1), 2, 3]!! assert typeof(c4) == '[3]u64' assert '$c4' == '[1, 2, 3]' - mut d1 := [1.1, 2.2, 3.3]!! assert typeof(d1) == '[3]f64' assert '$d1' == '[1.1, 2.2, 3.3]' - mut d2 := [f32(1.1), 2.2, 3.3]!! assert typeof(d2) == '[3]f32' assert '$d2' == '[1.1, 2.2, 3.3]' } fn test_fixed_type_init() { - a := [2]int - assert a == [2]int - assert a == [0,0]!! + a := [2]int{} + assert a == [2]int{} + assert a == [0, 0]!! assert a == a - mut c := [3,3]!! + mut c := [3, 3]!! assert a != c - assert c == [3,3]!! - c = [2]int + assert c == [3, 3]!! + c = [2]int{} assert a == c } fn test_fixed_custom_init() { a := [2]byte{init: 7} assert a == [byte(7), 7]!! - mut b := [3]int{} - assert b == [0,0,0]!! + assert b == [0, 0, 0]!! // assign - b = [3]int{init:5} - assert b == [5,5,5]!! + b = [3]int{init: 5} + assert b == [5, 5, 5]!! } diff --git a/vlib/v/tests/fixed_array_to_string_test.v b/vlib/v/tests/fixed_array_to_string_test.v index 68fefadf2d..53eda0ee28 100644 --- a/vlib/v/tests/fixed_array_to_string_test.v +++ b/vlib/v/tests/fixed_array_to_string_test.v @@ -1,46 +1,39 @@ fn test_fixed_array_to_string() { - mut a1 := [3]string + mut a1 := [3]string{} a1[0] = '1' a1[1] = '2' a1[2] = '3' assert '$a1' == "['1', '2', '3']" - - mut a2 := [2]string + mut a2 := [2]string{} a2[0] = 'a' a2[1] = 'b' assert '$a2' == "['a', 'b']" - - mut c1 := [3]int + mut c1 := [3]int{} c1[0] = 1 c1[1] = 2 c1[2] = 3 assert '$c1' == '[1, 2, 3]' - - mut c2 := [3]i16 + mut c2 := [3]i16{} c2[0] = 1 c2[1] = 2 c2[2] = 3 assert '$c2' == '[1, 2, 3]' - - mut c3 := [3]i64 + mut c3 := [3]i64{} c3[0] = 1 c3[1] = 2 c3[2] = 3 assert '$c3' == '[1, 2, 3]' - - mut c4 := [3]u64 + mut c4 := [3]u64{} c4[0] = 1 c4[1] = 2 c4[2] = 3 assert '$c4' == '[1, 2, 3]' - - mut d1 := [3]f64 + mut d1 := [3]f64{} d1[0] = 1.1 d1[1] = 2.2 d1[2] = 3.3 assert '$d1' == '[1.1, 2.2, 3.3]' - - mut d2 := [3]f32 + mut d2 := [3]f32{} d2[0] = 1.1 d2[1] = 2.2 d2[2] = 3.3 diff --git a/vlib/v/tests/fn_test.v b/vlib/v/tests/fn_test.v index deda0191b2..bc43dfe2b1 100644 --- a/vlib/v/tests/fn_test.v +++ b/vlib/v/tests/fn_test.v @@ -26,7 +26,7 @@ fn myfn4(string) fn foobar() -fn slopediv(num, den u32) int +fn slopediv(num u32, den u32) int type F1 = fn () diff --git a/vlib/v/tests/generic_fn_infer_test.v b/vlib/v/tests/generic_fn_infer_test.v index 3b9ab40c82..f3da4affb3 100644 --- a/vlib/v/tests/generic_fn_infer_test.v +++ b/vlib/v/tests/generic_fn_infer_test.v @@ -20,7 +20,7 @@ fn test_explicit_calls_should_also_work() { } // -fn choose4(a, b, c, d T) T { +fn choose4(a T, b T, c T, d T) T { // NB: a similar construct is used in prime31's via engine return a } diff --git a/vlib/v/tests/generics_test.v b/vlib/v/tests/generics_test.v index 2bc004638a..d08870fc3b 100644 --- a/vlib/v/tests/generics_test.v +++ b/vlib/v/tests/generics_test.v @@ -5,7 +5,7 @@ fn simple(p T) T { return p } -fn plus(xxx, b T) T { +fn plus(xxx T, b T) T { // x := a // y := b // ww := ww diff --git a/vlib/v/tests/map_and_array_with_fns_test.v b/vlib/v/tests/map_and_array_with_fns_test.v index 0d9c123070..c949b25f39 100644 --- a/vlib/v/tests/map_and_array_with_fns_test.v +++ b/vlib/v/tests/map_and_array_with_fns_test.v @@ -1,59 +1,59 @@ -fn foo(a, b string) int { - return 10 + a.len + b.len -} - -fn foo2(a, b string) int { - return 20 + a.len + b.len -} - -fn test_array_with_fns() { - mut a := [foo, foo2] - assert a.len == 2 - assert (a != [foo, foo2]) == false - assert (foo in a) == true - f0 := a[0] - assert f0('xx', '') == 12 - f1 := a[1] - assert f1('yyy', '') == 23 - a[0], a[1] = a[1], a[0] - f2 := a[0] - assert f2('zzzz', '') == 24 - f3 := a[1] - assert f3('aaaaa', '') == 15 - mut b := [foo] - assert (foo2 !in b) == true - b[0] = a[0] - f4 := b[0] - assert f4('bbbbbb', '') == 26 - for func in b { - assert func('ccccccc', '') == 27 - } - b = [] - b << foo - b << [foo2] - assert (b == [foo, foo2]) == true - f5 := b[0] - assert f5('dddddddd', '') == 18 -} - -fn test_map_with_fns() { - mut a := {'one':foo, 'two':foo2} - assert a.len == 2 - assert (a == {'one':foo, 'two':foo2}) == true - f0 := a['one'] - assert f0('xx', '') == 12 - f1 := a['two'] - assert f1('yyy', '') == 23 - a['one'], a['two'] = a['two'], a['one'] - f2 := a['one'] - assert f2('zzzz', '') == 24 - f3 := a['two'] - assert f3('aaaaa', '') == 15 - mut b := {'one':foo} - b['one'] = a['one'] - f4 := b['one'] - assert f4('bbbbbb', '') == 26 - for _, func in b { - assert func('ccccccc', '') == 27 - } -} +fn foo(a string, b string) int { + return 10 + a.len + b.len +} + +fn foo2(a string, b string) int { + return 20 + a.len + b.len +} + +fn test_array_with_fns() { + mut a := [foo, foo2] + assert a.len == 2 + assert (a != [foo, foo2]) == false + assert (foo in a) == true + f0 := a[0] + assert f0('xx', '') == 12 + f1 := a[1] + assert f1('yyy', '') == 23 + a[0], a[1] = a[1], a[0] + f2 := a[0] + assert f2('zzzz', '') == 24 + f3 := a[1] + assert f3('aaaaa', '') == 15 + mut b := [foo] + assert (foo2 !in b) == true + b[0] = a[0] + f4 := b[0] + assert f4('bbbbbb', '') == 26 + for func in b { + assert func('ccccccc', '') == 27 + } + b = [] + b << foo + b << [foo2] + assert (b == [foo, foo2]) == true + f5 := b[0] + assert f5('dddddddd', '') == 18 +} + +fn test_map_with_fns() { + mut a := {'one':foo, 'two':foo2} + assert a.len == 2 + assert (a == {'one':foo, 'two':foo2}) == true + f0 := a['one'] + assert f0('xx', '') == 12 + f1 := a['two'] + assert f1('yyy', '') == 23 + a['one'], a['two'] = a['two'], a['one'] + f2 := a['one'] + assert f2('zzzz', '') == 24 + f3 := a['two'] + assert f3('aaaaa', '') == 15 + mut b := {'one':foo} + b['one'] = a['one'] + f4 := b['one'] + assert f4('bbbbbb', '') == 26 + for _, func in b { + assert func('ccccccc', '') == 27 + } +} diff --git a/vlib/v/tests/modules/amodule/module.v b/vlib/v/tests/modules/amodule/module.v index acff83a2e4..067251ba02 100644 --- a/vlib/v/tests/modules/amodule/module.v +++ b/vlib/v/tests/modules/amodule/module.v @@ -1,14 +1,14 @@ module amodule -pub fn iadd(x, y int) int { +pub fn iadd(x int, y int) int { return x + y } -pub fn imul(x, y int) int { +pub fn imul(x int, y int) int { return x * y } // ///////////////////////////////////// -fn private_isub(x, y int) int { +fn private_isub(x int, y int) int { return x - y } diff --git a/vlib/v/tests/project_with_tests_for_main/main.v b/vlib/v/tests/project_with_tests_for_main/main.v index 1bbe17e30c..f346df30f8 100644 --- a/vlib/v/tests/project_with_tests_for_main/main.v +++ b/vlib/v/tests/project_with_tests_for_main/main.v @@ -1,4 +1,4 @@ -fn iadd(x, y int) int { +fn iadd(x int, y int) int { return x + y } diff --git a/vlib/v/tests/repeated_multiret_values_test.v b/vlib/v/tests/repeated_multiret_values_test.v index 6947840d7b..52033f12f1 100644 --- a/vlib/v/tests/repeated_multiret_values_test.v +++ b/vlib/v/tests/repeated_multiret_values_test.v @@ -1,5 +1,5 @@ // verify fix for #2913 -fn some_multiret_fn(a, b int) (int, int) { +fn some_multiret_fn(a int, b int) (int, int) { return a + 1, b + 1 } diff --git a/vlib/v/tests/reusable_mut_multiret_values_test.v b/vlib/v/tests/reusable_mut_multiret_values_test.v index 165e989f4f..1f6419bcc1 100644 --- a/vlib/v/tests/reusable_mut_multiret_values_test.v +++ b/vlib/v/tests/reusable_mut_multiret_values_test.v @@ -1,5 +1,5 @@ // verify fix for #2913 -fn some_multiret_fn(a, b int) (int, int) { +fn some_multiret_fn(a int, b int) (int, int) { return a + 1, b + 1 } diff --git a/vlib/v/tests/semaphore_test.v b/vlib/v/tests/semaphore_test.v index 483a5fa2d7..5079a996a8 100644 --- a/vlib/v/tests/semaphore_test.v +++ b/vlib/v/tests/semaphore_test.v @@ -1,10 +1,10 @@ import sync const ( - signals_per_thread = 100_000 + signals_per_thread = 100000 ) -fn send_signals(sem, sem_end sync.Semaphore) { +fn send_signals(sem sync.Semaphore, sem_end sync.Semaphore) { for _ in 0 .. signals_per_thread { sem.post() } diff --git a/vlib/v/tests/static_arrays_using_const_for_size_test.v b/vlib/v/tests/static_arrays_using_const_for_size_test.v index eb30a6bb2a..c8b0bd9d60 100644 --- a/vlib/v/tests/static_arrays_using_const_for_size_test.v +++ b/vlib/v/tests/static_arrays_using_const_for_size_test.v @@ -3,37 +3,37 @@ const ( ) fn test_hardcoded_static_arr() { - myints := [10]int + myints := [10]int{} size := sizeof(myints) assert size == 40 } fn test_const_based_static_arr() { - myints := [sbuffer_size]int + myints := [sbuffer_size]int{} size := sizeof(myints) assert size == 40 } fn test_const_based_static_arr_of_f64() { - myf64 := [sbuffer_size]f64 + myf64 := [sbuffer_size]f64{} size := sizeof(myf64) assert size == 80 } fn test_const_based_static_arr_of_f32() { - myf32 := [sbuffer_size]f32 + myf32 := [sbuffer_size]f32{} size := sizeof(myf32) assert size == 40 } fn test_const_based_static_arr_of_i8() { - myi8 := [sbuffer_size]i8 + myi8 := [sbuffer_size]i8{} size := sizeof(myi8) assert size == 10 } fn test_const_based_static_arr_of_i16() { - myi16 := [sbuffer_size]i16 + myi16 := [sbuffer_size]i16{} size := sizeof(myi16) assert size == 20 }