diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index 5afe4a6a7c..f42fa3852e 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -358,12 +358,19 @@ pub fn prepare_test_session(zargs string, folder string, oskipped []string, main mut mains := []string{} mut skipped := oskipped.clone() next_file: for f in files { - if f.contains('modules') || f.contains('preludes') { + fnormalised := f.replace('\\', '/') + // NB: a `testdata` folder, is the preferred name of a folder, containing V code, + // that you *do not want* the test framework to find incidentally for various reasons, + // for example module import tests, or subtests, that are compiled/run by other parent tests + // in specific configurations, etc. + if fnormalised.contains('testdata/') || fnormalised.contains('modules/') + || f.contains('preludes/') { continue } $if windows { // skip pico and process/command examples on windows - if f.ends_with('examples\\pico\\pico.v') || f.ends_with('examples\\process\\command.v') { + if fnormalised.ends_with('examples/pico/pico.v') + || fnormalised.ends_with('examples/process/command.v') { continue } } diff --git a/doc/docs.md b/doc/docs.md index 5ed63297af..4a0b1e8d06 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -3219,6 +3219,25 @@ To test an entire module, use `v test mymodule`. You can also use `v test .` to everything inside your current folder (and subfolders). You can pass the `-stats` option to see more details about the individual tests run. +You can put additional test data, including .v source files in a folder, named +`testdata`, right next to your _test.v files. V's test framework will *ignore* +such folders, while scanning for tests to run. This is usefull, if you want to +put .v files with invalid V source code, or other tests, including known +failing ones, that should be run in a specific way/options by a parent _test.v +file. + +NB: the path to the V compiler, is available through @VEXE, so a _test.v +file, can easily run *other* test files like this: +```v oksyntax +import os + +fn test_subtest() { + res := os.execute('${@VEXE} other_test.v') + assert res.exit_code == 1 + assert res.output.contains('other_test.v does not exist') +} +``` + ## Memory management V avoids doing unnecessary allocations in the first place by using value types,