v2 / vlib / v / util / vtest / vtest.v
29 lines · 26 sloc · 639 bytes · 1a35a783f1e4e8ce6eda182354af83763633caed
Raw
1module vtest
2
3import os
4
5@[params]
6pub struct FilterVTestConfig {
7pub:
8 basepath string
9 fix_slashes bool = true
10}
11
12// if VTEST_ONLY env var is set, returns tests that match the query
13pub fn filter_vtest_only(paths []string, config FilterVTestConfig) []string {
14 mut res := []string{}
15 patterns := os.getenv('VTEST_ONLY').split(',')
16 for relative_path in paths {
17 mut file := relative_path
18 if config.basepath != '' {
19 file = os.join_path_single(config.basepath, file)
20 }
21 if config.fix_slashes {
22 file = file.replace('\\', '/')
23 }
24 if patterns.len > 0 && patterns.any(file.contains(it)) {
25 res << file
26 }
27 }
28 return res
29}
30