| 1 | module vtest |
| 2 | |
| 3 | import os |
| 4 | |
| 5 | @[params] |
| 6 | pub struct FilterVTestConfig { |
| 7 | pub: |
| 8 | basepath string |
| 9 | fix_slashes bool = true |
| 10 | } |
| 11 | |
| 12 | // if VTEST_ONLY env var is set, returns tests that match the query |
| 13 | pub 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 | |