From ae8f7cf569ff872289b07da716f964cee6264b60 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 1 Jun 2020 18:24:38 +0300 Subject: [PATCH] tests: fix some tests, that failed due to the stricter immutable checks --- vlib/encoding/csv/writer.v | 1 + vlib/eventbus/eventbus.v | 1 - vlib/net/websocket/ws.v | 4 ++-- vlib/time/stopwatch_test.v | 4 ++-- vlib/v/checker/tests/const_field_add_err.out | 2 +- vlib/v/checker/tests/const_field_dec_err.out | 2 +- vlib/v/checker/tests/const_field_inc_err.out | 2 +- vlib/v/checker/tests/const_field_sub_err.out | 2 +- vlib/v/fmt/fmt.v | 4 ++-- vlib/v/scanner/scanner_test.v | 4 ++-- vlib/v/tests/live_test.v | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) diff --git a/vlib/encoding/csv/writer.v b/vlib/encoding/csv/writer.v index 5aba0cffbd..a1320efadf 100644 --- a/vlib/encoding/csv/writer.v +++ b/vlib/encoding/csv/writer.v @@ -7,6 +7,7 @@ module csv import strings struct Writer { +mut: sb strings.Builder pub mut: use_crlf bool diff --git a/vlib/eventbus/eventbus.v b/vlib/eventbus/eventbus.v index 66dbc6588e..aef2e9db8f 100644 --- a/vlib/eventbus/eventbus.v +++ b/vlib/eventbus/eventbus.v @@ -28,7 +28,6 @@ pub struct EventBus { pub mut: registry &Registry publisher &Publisher -pub: subscriber &Subscriber } diff --git a/vlib/net/websocket/ws.v b/vlib/net/websocket/ws.v index 1de9384d08..489f873647 100644 --- a/vlib/net/websocket/ws.v +++ b/vlib/net/websocket/ws.v @@ -15,12 +15,12 @@ pub struct Client { retry int eb &eventbus.EventBus is_ssl bool - lock &sync.Mutex = sync.new_mutex() - write_lock &sync.Mutex = sync.new_mutex() // subprotocol_len int // cwebsocket_subprotocol *subprotocol; // cwebsocket_subprotocol *subprotocols[]; mut: + lock &sync.Mutex = sync.new_mutex() + write_lock &sync.Mutex = sync.new_mutex() state State socket net.Socket flags []Flag diff --git a/vlib/time/stopwatch_test.v b/vlib/time/stopwatch_test.v index 69c87071be..bc82fc2cf1 100644 --- a/vlib/time/stopwatch_test.v +++ b/vlib/time/stopwatch_test.v @@ -4,7 +4,7 @@ import time // time than you have specified. To avoid false positives from CI test // failures, some of the asserts will be run only if you pass `-d stopwatch` fn test_stopwatch_works_as_intended() { - sw := time.new_stopwatch({}) + mut sw := time.new_stopwatch({}) // sample code that you want to measure: println('Hello world') time.sleep_ms(1) @@ -15,7 +15,7 @@ fn test_stopwatch_works_as_intended() { fn test_stopwatch_time_between_pause_and_start_should_be_skipped_in_elapsed() { println('Testing pause function') - sw := time.new_stopwatch({}) + mut sw := time.new_stopwatch({}) time.sleep_ms(10) // A eprintln('Elapsed after 10ms nap: ${sw.elapsed().milliseconds()}ms') assert sw.elapsed().milliseconds() >= 10 diff --git a/vlib/v/checker/tests/const_field_add_err.out b/vlib/v/checker/tests/const_field_add_err.out index dcae543d9f..6a4ebc25bc 100644 --- a/vlib/v/checker/tests/const_field_add_err.out +++ b/vlib/v/checker/tests/const_field_add_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/const_field_add_err.v:6:2: error: cannot assign to constant `a` +vlib/v/checker/tests/const_field_add_err.v:6:2: error: cannot modify constant `a` 4 | 5 | fn main() { 6 | a += 1 diff --git a/vlib/v/checker/tests/const_field_dec_err.out b/vlib/v/checker/tests/const_field_dec_err.out index 27e96e62c5..a40e1d858a 100644 --- a/vlib/v/checker/tests/const_field_dec_err.out +++ b/vlib/v/checker/tests/const_field_dec_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/const_field_dec_err.v:6:2: error: cannot assign to constant `a` +vlib/v/checker/tests/const_field_dec_err.v:6:2: error: cannot modify constant `a` 4 | 5 | fn main() { 6 | a-- diff --git a/vlib/v/checker/tests/const_field_inc_err.out b/vlib/v/checker/tests/const_field_inc_err.out index b35ef2c98b..c3a44f180e 100644 --- a/vlib/v/checker/tests/const_field_inc_err.out +++ b/vlib/v/checker/tests/const_field_inc_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/const_field_inc_err.v:6:2: error: cannot assign to constant `a` +vlib/v/checker/tests/const_field_inc_err.v:6:2: error: cannot modify constant `a` 4 | 5 | fn main() { 6 | a++ diff --git a/vlib/v/checker/tests/const_field_sub_err.out b/vlib/v/checker/tests/const_field_sub_err.out index daf95cbe53..fa0e8fb182 100644 --- a/vlib/v/checker/tests/const_field_sub_err.out +++ b/vlib/v/checker/tests/const_field_sub_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/const_field_sub_err.v:6:2: error: cannot assign to constant `a` +vlib/v/checker/tests/const_field_sub_err.v:6:2: error: cannot modify constant `a` 4 | 5 | fn main() { 6 | a -= 1 diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 93d488e308..899c076029 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -16,10 +16,10 @@ const ( pub struct Fmt { pub: - out strings.Builder - out_imports strings.Builder table &table.Table pub mut: + out_imports strings.Builder + out strings.Builder indent int empty_line bool line_len int diff --git a/vlib/v/scanner/scanner_test.v b/vlib/v/scanner/scanner_test.v index 6afe2400c3..609d257f49 100644 --- a/vlib/v/scanner/scanner_test.v +++ b/vlib/v/scanner/scanner_test.v @@ -89,7 +89,7 @@ fn test_scan() { assert t == 2 }) - tfn := TestFn{} + mut tfn := TestFn{} tfn.tst_1() tfn.tst_2(fn(i int){ t := i + 1 @@ -102,7 +102,7 @@ fn test_scan() { // Test @STRUCT assert @STRUCT == '' - ts := TestStruct { test: "test" } + mut ts := TestStruct { test: "test" } ts.test_struct() r1 := ts.test_struct_w_return() r2 := ts.test_struct_w_high_order(fn(i int)string{ diff --git a/vlib/v/tests/live_test.v b/vlib/v/tests/live_test.v index b7debc74c7..668cd88bc9 100755 --- a/vlib/v/tests/live_test.v +++ b/vlib/v/tests/live_test.v @@ -46,7 +46,7 @@ import os import live fn append_to_file(fname, s string) { - f := os.open_append(fname) or { + mut f := os.open_append(fname) or { println('>>>> could not open file \$fname for appending, err: \$err ') return }