tests: ignore `testdata` folders while scanning for tests and .v files

pull/10330/head^2
Delyan Angelov 2021-06-02 21:19:03 +03:00
parent 1747e546bf
commit bf623e191f
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 28 additions and 2 deletions

View File

@ -358,12 +358,19 @@ pub fn prepare_test_session(zargs string, folder string, oskipped []string, main
mut mains := []string{} mut mains := []string{}
mut skipped := oskipped.clone() mut skipped := oskipped.clone()
next_file: for f in files { 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 continue
} }
$if windows { $if windows {
// skip pico and process/command examples on 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 continue
} }
} }

View File

@ -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` everything inside your current folder (and subfolders). You can pass the `-stats`
option to see more details about the individual tests run. 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 ## Memory management
V avoids doing unnecessary allocations in the first place by using value types, V avoids doing unnecessary allocations in the first place by using value types,