From 5be2b1d9cd1f93efc8a776455991080648a51fb9 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 30 Apr 2026 06:16:49 +0300 Subject: [PATCH] all: fix more tests --- .github/workflows/windows-install-sqlite.bat | 3 ++- GNUmakefile | 3 +++ cmd/tools/modules/vshare/clipboard_test.v | 7 ++++++- cmd/tools/translate_test.v | 20 +++++++++++++++---- cmd/tools/vtest-cleancode.v | 5 ++++- cmd/tools/vtest_test.v | 2 +- vlib/builtin/builtin_print_write_error_test.v | 2 +- vlib/os/file.c.v | 4 ++-- vlib/os/os_nix.c.v | 6 ++++-- vlib/os/os_windows.c.v | 17 +++++++++++++--- vlib/sync/waitgroup.c.v | 1 + vlib/v/gen/c/embed.v | 5 +++-- .../c/testdata/embed_issue_12035.c.must_have | 4 ++-- .../c/testdata/embed_with_prod.c.must_have | 2 +- .../testdata/embed_with_prod_zlib.c.must_have | 2 +- vlib/x/templating/dtm2/README.md | 3 ++- 16 files changed, 63 insertions(+), 23 deletions(-) diff --git a/.github/workflows/windows-install-sqlite.bat b/.github/workflows/windows-install-sqlite.bat index 45dd54090..ad03efc06 100644 --- a/.github/workflows/windows-install-sqlite.bat +++ b/.github/workflows/windows-install-sqlite.bat @@ -1,3 +1,4 @@ REM This file should be run from the top folder of the V compiler itself. -v vlib/db/sqlite/install_thirdparty_sqlite.vsh +python .github\workflows\windows-install-sqlite.py +exit /b %ERRORLEVEL% diff --git a/GNUmakefile b/GNUmakefile index 50dd20288..6b4da4eaa 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -81,6 +81,9 @@ ifdef ANDROID_ROOT ANDROID := 1 undefine LINUX TCCOS := android +ifneq ($(wildcard $(PREFIX)/lib/libexecinfo.*),) +LDFLAGS += -lexecinfo +endif endif ##### diff --git a/cmd/tools/modules/vshare/clipboard_test.v b/cmd/tools/modules/vshare/clipboard_test.v index 25a18c067..270320a7c 100644 --- a/cmd/tools/modules/vshare/clipboard_test.v +++ b/cmd/tools/modules/vshare/clipboard_test.v @@ -46,7 +46,12 @@ fn test_copy_to_clipboard_with_commands_uses_the_first_working_command() { command: fake_clipboard_command() }, ]) - assert os.read_file(output_path)! == 'https://play.vlang.io/p/test' + output := os.read_file(output_path)! + $if windows { + assert output.trim_right('\r\n') == 'https://play.vlang.io/p/test' + } $else { + assert output == 'https://play.vlang.io/p/test' + } } fn fake_clipboard_command() string { diff --git a/cmd/tools/translate_test.v b/cmd/tools/translate_test.v index e1c000146..5a6cdbf32 100644 --- a/cmd/tools/translate_test.v +++ b/cmd/tools/translate_test.v @@ -14,13 +14,17 @@ fn test_translate_legacy_wrapper_flag_uses_wrapper_mode() { sample_path := os.join_path(test_dir, 'usersapi.c') args_out := os.join_path(test_dir, 'c2v_args.txt') os.write_file(sample_path, 'int usersapi_get_number_of_users(void) { return 1; }\n')! + original_c2v_args_out := os.getenv('C2V_ARGS_OUT') + original_vmodules := os.getenv('VMODULES') + os.setenv('C2V_ARGS_OUT', args_out, true) + os.setenv('VMODULES', vmodules_dir, true) + defer { + restore_env('C2V_ARGS_OUT', original_c2v_args_out) + restore_env('VMODULES', original_vmodules) + } mut process := os.new_process(@VEXE) process.set_work_folder(@VEXEROOT) process.set_args(['translate', '-wrapper', sample_path]) - process.set_environment({ - 'C2V_ARGS_OUT': args_out - 'VMODULES': vmodules_dir - }) process.set_redirect_stdio() process.wait() stdout := process.stdout_slurp() @@ -48,3 +52,11 @@ fn compile_fake_c2v(vmodules_dir string) ! { fn exe_suffix() string { return if os.user_os() == 'windows' { '.exe' } else { '' } } + +fn restore_env(name string, value string) { + if value == '' { + os.unsetenv(name) + } else { + os.setenv(name, value, true) + } +} diff --git a/cmd/tools/vtest-cleancode.v b/cmd/tools/vtest-cleancode.v index 493e04aaf..ea2cb4a06 100644 --- a/cmd/tools/vtest-cleancode.v +++ b/cmd/tools/vtest-cleancode.v @@ -7,6 +7,7 @@ import arrays const vet_known_failing = [ 'do_not_delete_this', + 'vlib/v/checker/tests/modules/indirect_import_unknown_module/main.v', ] const vet_known_failing_windows = [ @@ -76,11 +77,13 @@ fn tsession(vargs string, tool_source string, tool_cmd string, tool_args string, } fn v_test_vetting(vargs string) ! { - expanded_vet_list := util.find_all_v_files(vet_folders)! mut vet_known_exceptions := vet_known_failing.clone() if os.user_os() == 'windows' { vet_known_exceptions << vet_known_failing_windows } + vet_known_exceptions = vet_known_exceptions.map(os.abs_path(os.join_path(vroot, it))) + expanded_vet_list := + (util.find_all_v_files(vet_folders)!).filter(os.abs_path(it) !in vet_known_exceptions) vet_session := tsession(vargs, 'vvet', '${os.quoted_path(vexe)} vet', 'vet', expanded_vet_list, vet_known_exceptions) diff --git a/cmd/tools/vtest_test.v b/cmd/tools/vtest_test.v index 850503be4..d92db5bae 100644 --- a/cmd/tools/vtest_test.v +++ b/cmd/tools/vtest_test.v @@ -116,7 +116,7 @@ fn test_wimpure_v_warnings_are_shown_for_test_files() { } fn test_js_runtime_errors_are_shown_for_js_tests() { - if @CCOMPILER.contains('musl') { + if @CCOMPILER.contains('musl') || os.getenv('VFLAGS').contains('musl') { return } if os.execute('node --version').exit_code != 0 { diff --git a/vlib/builtin/builtin_print_write_error_test.v b/vlib/builtin/builtin_print_write_error_test.v index 2ed87dc21..33f3c44a2 100644 --- a/vlib/builtin/builtin_print_write_error_test.v +++ b/vlib/builtin/builtin_print_write_error_test.v @@ -40,7 +40,7 @@ fn test_println_does_not_hang_on_failed_stdout_write() { } p.close() } - max_wait_iterations := $if s390x { 1200 } $else { 300 } + max_wait_iterations := $if s390x || rv64 { 1200 } $else { 300 } for _ in 0 .. max_wait_iterations { if !p.is_alive() { break diff --git a/vlib/os/file.c.v b/vlib/os/file.c.v index 8311ab87d..cb38e6d2e 100644 --- a/vlib/os/file.c.v +++ b/vlib/os/file.c.v @@ -203,7 +203,7 @@ pub fn (mut f File) reopen(path string, mode string) ! { // read implements the Reader interface. pub fn (f &File) read(mut buf []u8) !int { - if !f.is_opened { + if !f.is_opened || isnil(f.cfile) { return error_file_not_opened() } if buf.len == 0 { @@ -231,7 +231,7 @@ pub fn (f &File) read(mut buf []u8) !int { // write implements the Writer interface. // It returns how many bytes were actually written. pub fn (mut f File) write(buf []u8) !int { - if !f.is_opened { + if !f.is_opened || isnil(f.cfile) { return error_file_not_opened() } /* diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v index 3ab1e46fc..73e19cdc2 100644 --- a/vlib/os/os_nix.c.v +++ b/vlib/os/os_nix.c.v @@ -437,8 +437,10 @@ pub fn (mut f File) close() { return } f.is_opened = false - C.fflush(f.cfile) - C.fclose(f.cfile) + cfile := f.cfile + f.cfile = unsafe { nil } + C.fflush(cfile) + C.fclose(cfile) } fn C.mkstemp(stemplate &u8) i32 diff --git a/vlib/os/os_windows.c.v b/vlib/os/os_windows.c.v index 7131e767d..a21701ea0 100644 --- a/vlib/os/os_windows.c.v +++ b/vlib/os/os_windows.c.v @@ -210,7 +210,16 @@ fn decode_windows_captured_output(raw string) string { if !has_null { return raw } - // Contains null bytes — likely corrupted UTF-16LE. + mut nulls := 0 + for i in 0 .. raw.len { + if raw[i] == 0 { + nulls++ + } + } + if nulls * 4 < raw.len { + return raw + } + // Contains many null bytes - likely corrupted UTF-16LE. // Strip null bytes and normalize \r\n to \n (text-mode artifacts). mut cleaned := strings.new_builder(raw.len) for i in 0 .. raw.len { @@ -631,8 +640,10 @@ pub fn (mut f File) close() { return } f.is_opened = false - C.fflush(f.cfile) - C.fclose(f.cfile) + cfile := f.cfile + f.cfile = unsafe { nil } + C.fflush(cfile) + C.fclose(cfile) } pub struct ExceptionRecord { diff --git a/vlib/sync/waitgroup.c.v b/vlib/sync/waitgroup.c.v index 1ee5a010c..007f9e5fc 100644 --- a/vlib/sync/waitgroup.c.v +++ b/vlib/sync/waitgroup.c.v @@ -43,6 +43,7 @@ pub fn new_waitgroup() &WaitGroup { // init initializes a WaitGroup. pub fn (mut wg WaitGroup) init() { + C.atomic_store_u64(voidptr(&wg.state), 0) wg.sem.init(0) } diff --git a/vlib/v/gen/c/embed.v b/vlib/v/gen/c/embed.v index 26fb33da2..137b22068 100644 --- a/vlib/v/gen/c/embed.v +++ b/vlib/v/gen/c/embed.v @@ -143,7 +143,8 @@ fn (mut g Gen) gen_embedded_data() { // like the `rcc` tool in Qt? */ // Declare the index before any generated helper references it, to keep MSVC happy. - g.embedded_data.writeln('static const v__embed_file__EmbedFileIndexEntry _v_embed_file_index[];') + index_len := g.embedded_files.len + 1 + g.embedded_data.writeln('static const v__embed_file__EmbedFileIndexEntry _v_embed_file_index[${index_len}];') for i, emfile in g.embedded_files { g.embedded_data.write_string('static const unsigned char _v_embed_blob_${i}[${emfile.bytes.len}] = {\n ') for j := 0; j < emfile.bytes.len; j++ { @@ -160,7 +161,7 @@ fn (mut g Gen) gen_embedded_data() { g.embedded_data.writeln('\n};') } g.embedded_data.writeln('') - g.embedded_data.writeln('static const v__embed_file__EmbedFileIndexEntry _v_embed_file_index[] = {') + g.embedded_data.writeln('static const v__embed_file__EmbedFileIndexEntry _v_embed_file_index[${index_len}] = {') for i, emfile in g.embedded_files { g.embedded_data.writeln('\t{${i}, { .str=(byteptr)("${cestring(emfile.rpath)}"), .len=${emfile.rpath.len}, .is_lit=1 }, { .str=(byteptr)("${cestring(emfile.compression_type)}"), .len=${emfile.compression_type.len}, .is_lit=1 }, (byteptr)_v_embed_blob_${i}},') } diff --git a/vlib/v/gen/c/testdata/embed_issue_12035.c.must_have b/vlib/v/gen/c/testdata/embed_issue_12035.c.must_have index 98f362eab..ffe665cbb 100644 --- a/vlib/v/gen/c/testdata/embed_issue_12035.c.must_have +++ b/vlib/v/gen/c/testdata/embed_issue_12035.c.must_have @@ -1,3 +1,3 @@ -static const v__embed_file__EmbedFileIndexEntry _v_embed_file_index[]; -static const v__embed_file__EmbedFileIndexEntry _v_embed_file_index[] = { +static const v__embed_file__EmbedFileIndexEntry _v_embed_file_index[2]; +static const v__embed_file__EmbedFileIndexEntry _v_embed_file_index[2] = { v__embed_file__EmbedFileData _v_embed_file_metadata(u64 ef_hash) { diff --git a/vlib/v/gen/c/testdata/embed_with_prod.c.must_have b/vlib/v/gen/c/testdata/embed_with_prod.c.must_have index ca42b98d0..7e5439a93 100644 --- a/vlib/v/gen/c/testdata/embed_with_prod.c.must_have +++ b/vlib/v/gen/c/testdata/embed_with_prod.c.must_have @@ -4,7 +4,7 @@ static const unsigned char _v_embed_blob_0[171] = { 0x2f,0x2f,0x20,0x76,0x74,0x65,0x73,0x74,0x20,0x76,0x66,0x6c,0x61,0x67,0x73,0x3a, -const v__embed_file__EmbedFileIndexEntry _v_embed_file_index[] = { +const v__embed_file__EmbedFileIndexEntry _v_embed_file_index[2] = { {0, { .str=(byteptr)("embed.vv"), .len=8, .is_lit=1 }, { .str=(byteptr)("none"), .len=4, .is_lit=1 }, (byteptr)_v_embed_blob_0}, {-1, { .str=(byteptr)(""), .len=0, .is_lit=1 }, { .str=(byteptr)(""), .len=0, .is_lit=1 }, NULL} }; diff --git a/vlib/v/gen/c/testdata/embed_with_prod_zlib.c.must_have b/vlib/v/gen/c/testdata/embed_with_prod_zlib.c.must_have index a38b6a973..9beff83d5 100644 --- a/vlib/v/gen/c/testdata/embed_with_prod_zlib.c.must_have +++ b/vlib/v/gen/c/testdata/embed_with_prod_zlib.c.must_have @@ -4,7 +4,7 @@ static const unsigned char _v_embed_blob_0[142] = { 0x78,0x01,0x05,0x00,0x41,0x0a,0x84,0x20,0xf0,0xac,0xaf,0x98,0xc3,0xc2,0xea,0x21, -const v__embed_file__EmbedFileIndexEntry _v_embed_file_index[] = { +const v__embed_file__EmbedFileIndexEntry _v_embed_file_index[2] = { {0, { .str=(byteptr)("embed.vv"), .len=8, .is_lit=1 }, { .str=(byteptr)("zlib"), .len=4, .is_lit=1 }, (byteptr)_v_embed_blob_0}, {-1, { .str=(byteptr)(""), .len=0, .is_lit=1 }, { .str=(byteptr)(""), .len=0, .is_lit=1 }, NULL} }; diff --git a/vlib/x/templating/dtm2/README.md b/vlib/x/templating/dtm2/README.md index 7e2f682db..862a63516 100644 --- a/vlib/x/templating/dtm2/README.md +++ b/vlib/x/templating/dtm2/README.md @@ -353,7 +353,8 @@ vlib/x/templating/dtm2/benchmarks/run_dtm2_benchmark.sh Useful options: - `DTM2_BENCH_MODE=prod|prod_o2|dev` -- `DTM2_BENCH_CASE=all|small_hot|small_cold|many_hot|many_cold|include_hot|include_cold|xml_hot|xml_cold` +- `DTM2_BENCH_CASE=all|small_hot|small_cold|many_hot|many_cold|include_hot` +- `DTM2_BENCH_CASE=include_cold|xml_hot|xml_cold` - `DTM2_BENCH_ITERATIONS=50000` - `DTM2_BENCH_COLD_ITERATIONS=500` - `DTM2_BENCH_PLACEHOLDERS=50` -- 2.39.5