From 409a4f33a1886f5054c76ca65e180c23c984a529 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 16 Oct 2022 22:40:17 +0300 Subject: [PATCH] tools: add report_v_module_folders_without_tests.v . Use it to discover other modules without _test.v files. Add simple ones, to ensure CI can find more breakage on future wide changes to vlib/ --- .../report_v_module_folders_without_tests.v | 68 +++++++++++++++++++ vlib/hash/hash_compiles_test.v | 5 ++ vlib/mssql/stmt_handle.v | 8 +-- vlib/net/mbedtls/mbedtls_compiles_test.v | 6 ++ ...openssl_test.v => openssl_compiles_test.v} | 0 vlib/net/ssl/ssl_compiles_test.v | 5 ++ 6 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 cmd/tools/report_v_module_folders_without_tests.v create mode 100644 vlib/hash/hash_compiles_test.v create mode 100644 vlib/net/mbedtls/mbedtls_compiles_test.v rename vlib/net/openssl/{openssl_test.v => openssl_compiles_test.v} (100%) create mode 100644 vlib/net/ssl/ssl_compiles_test.v diff --git a/cmd/tools/report_v_module_folders_without_tests.v b/cmd/tools/report_v_module_folders_without_tests.v new file mode 100644 index 0000000000..b3036ec433 --- /dev/null +++ b/cmd/tools/report_v_module_folders_without_tests.v @@ -0,0 +1,68 @@ +module main + +import os + +const vexe = @VEXE + +const known_skip_patterns_env = os.getenv('VKNOWN_SKIP_PATTERNS') + +const known_folder_patterns_that_are_not_module_ones = [ + 'vlib/sync/bench', + '/tests', + '/testdata', + '/preludes_js', + 'vlib/builtin/js', // TODO: fix compiler panic + 'vlib/fontstash', // used by `gg` + 'vlib/sokol/sfons', // used by `gg`, and by examples/sokol/fonts.v + 'vlib/sokol/sapp', // used by `gg`, and many examples/ + 'vlib/sokol/gfx', // used by `gg`, `x.ttf` + 'vlib/sokol/sgl', // used by `gg` + 'vlib/toml', // toml is well tested, even if the top level folder does not have _test.v files, the ones below do + 'vlib/v/', // the compiler itself is well tested +] + +fn main() { + mut places := if os.args.len > 1 { + os.args#[1..] + } else { + eprintln('> check the current folder only by default ...') + ['.'] + } + mut known_skip_patterns := known_folder_patterns_that_are_not_module_ones.clone() + if known_skip_patterns_env != '' { + known_skip_patterns = known_skip_patterns_env.split(',').filter(it != '') + } + for path in places { + eprintln('> Checking folder: `$path` ...') + mut found := 0 + files := os.walk_ext(path, '.v') + mut v_files := map[string]int{} + mut v_test_files := map[string]int{} + for f in files { + folder := os.to_slash(os.dir(f)) + if known_skip_patterns.any(f.contains(it)) { + continue + } + if f.ends_with('.v') { + v_files[folder]++ + } + if f.ends_with('_test.v') { + v_test_files[folder]++ + } + } + eprintln('> Found ${v_files.len:5} potential V module folders (containing .v files).') + for folder, n_v_files in v_files { + n_test_v_files := v_test_files[folder] + if n_v_files > 1 && n_test_v_files == 0 { + println('> ${n_test_v_files:5} _test.v files, with ${n_v_files:5} .v files, in folder: $folder') + compilation := os.execute('${os.quoted_path(vexe)} -shared -W -Wfatal-errors -check ${os.quoted_path(folder)}') + if compilation.exit_code != 0 { + eprintln('> $folder has parser/checker errors!') + eprintln(compilation.output) + } + found++ + } + } + eprintln('> Found $found module folders without _test.v files in `$path` .') + } +} diff --git a/vlib/hash/hash_compiles_test.v b/vlib/hash/hash_compiles_test.v new file mode 100644 index 0000000000..2b12f66344 --- /dev/null +++ b/vlib/hash/hash_compiles_test.v @@ -0,0 +1,5 @@ +import hash + +fn test_hash_compiles() { + assert hash.sum64_string('abc', 5).hex_full() == 'ce2703347d216491' +} diff --git a/vlib/mssql/stmt_handle.v b/vlib/mssql/stmt_handle.v index 392d983e6c..a946bcf5aa 100644 --- a/vlib/mssql/stmt_handle.v +++ b/vlib/mssql/stmt_handle.v @@ -68,8 +68,8 @@ fn (mut h HStmt) prepare_read() ? { column_count := h.retrieve_column_count()? h.column_count = column_count // remember the count because read will need it - h.buffers = [][]char{len: h.column_count, cap: h.column_count} - h.indicators = []C.SQLLEN{len: h.column_count, cap: h.column_count} + h.buffers = [][]char{len: h.column_count} + h.indicators = []C.SQLLEN{len: h.column_count} for i := 0; i < h.column_count; i++ { i_col := C.SQLUSMALLINT(i + 1) // col number starts with 1 @@ -82,7 +82,7 @@ fn (mut h HStmt) prepare_read() ? { // buffer allocation is the size + 1 to include termination char, since SQL_DESC_LENGTH does not include it. allocate_size := size_ret + C.SQLLEN(1) allocate_size_int := int(allocate_size) - buff := []char{len: allocate_size_int, cap: allocate_size_int} + buff := []char{len: allocate_size_int} // bind the buffer retcode = C.SQLBindCol(h.hstmt, C.SQLUSMALLINT(i_col), C.SQLSMALLINT(C.SQL_C_CHAR), @@ -112,7 +112,7 @@ fn (h HStmt) read_rows() ?[][]string { if retcode == C.SQLRETURN(C.SQL_SUCCESS) || retcode == C.SQLRETURN(C.SQL_SUCCESS_WITH_INFO) { // copy buffered result to res for content in h.buffers { - row << string(content) + row << unsafe { cstring_to_vstring(content.data) } } } else { if retcode != C.SQLRETURN(C.SQL_NO_DATA) { diff --git a/vlib/net/mbedtls/mbedtls_compiles_test.v b/vlib/net/mbedtls/mbedtls_compiles_test.v new file mode 100644 index 0000000000..b5dfd2e3f1 --- /dev/null +++ b/vlib/net/mbedtls/mbedtls_compiles_test.v @@ -0,0 +1,6 @@ +import net.mbedtls + +fn test_mbedtls_compiles() { + assert mbedtls.is_used == 1 + assert true +} diff --git a/vlib/net/openssl/openssl_test.v b/vlib/net/openssl/openssl_compiles_test.v similarity index 100% rename from vlib/net/openssl/openssl_test.v rename to vlib/net/openssl/openssl_compiles_test.v diff --git a/vlib/net/ssl/ssl_compiles_test.v b/vlib/net/ssl/ssl_compiles_test.v new file mode 100644 index 0000000000..c8bce84b6d --- /dev/null +++ b/vlib/net/ssl/ssl_compiles_test.v @@ -0,0 +1,5 @@ +import net.ssl + +fn test_ssl_compiles() { + assert sizeof(ssl.SSLConn) > 0 +}