2021-06-30 08:30:18 +03:00
|
|
|
import os
|
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
fn deep_glob() ! {
|
|
|
|
os.chdir(@VMODROOT)!
|
2021-06-30 08:30:18 +03:00
|
|
|
matches := os.glob('vlib/v/*/*.v') or { panic(err) }
|
|
|
|
assert matches.len > 10
|
|
|
|
assert 'vlib/v/ast/ast.v' in matches
|
|
|
|
assert 'vlib/v/ast/table.v' in matches
|
|
|
|
assert 'vlib/v/token/token.v' in matches
|
|
|
|
for f in matches {
|
|
|
|
if !f.starts_with('vlib/v/') {
|
|
|
|
assert false
|
|
|
|
}
|
|
|
|
assert f.ends_with('.v')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
fn redeep_glob() ! {
|
|
|
|
os.chdir(@VMODROOT)!
|
2021-07-09 03:27:16 +03:00
|
|
|
matches := os.glob('vlib/v/**/*.v') or { panic(err) }
|
|
|
|
assert matches.len > 10
|
|
|
|
assert 'vlib/v/ast/ast.v' in matches
|
|
|
|
assert 'vlib/v/ast/table.v' in matches
|
|
|
|
assert 'vlib/v/token/token.v' in matches
|
|
|
|
for f in matches {
|
|
|
|
if !f.starts_with('vlib/v/') {
|
|
|
|
assert false
|
|
|
|
}
|
|
|
|
assert f.ends_with('.v')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-21 19:45:43 +03:00
|
|
|
fn test_glob_can_find_v_files_3_levels_deep() {
|
2021-06-30 08:30:18 +03:00
|
|
|
$if !windows {
|
2022-10-16 09:28:57 +03:00
|
|
|
deep_glob()!
|
|
|
|
redeep_glob()!
|
2021-06-30 08:30:18 +03:00
|
|
|
}
|
|
|
|
assert true
|
|
|
|
}
|
|
|
|
|
2022-09-21 19:45:43 +03:00
|
|
|
fn test_glob_can_find_files_in_current_folder() {
|
2022-10-16 09:28:57 +03:00
|
|
|
os.chdir(@VMODROOT)!
|
|
|
|
matches := os.glob('*')!
|
2021-07-22 13:26:23 +03:00
|
|
|
assert '.gitignore' in matches
|
|
|
|
assert 'make.bat' in matches
|
|
|
|
assert 'Makefile' in matches
|
|
|
|
assert 'Dockerfile' in matches
|
2021-06-30 08:30:18 +03:00
|
|
|
assert 'README.md' in matches
|
|
|
|
assert 'v.mod' in matches
|
|
|
|
assert 'cmd/' in matches
|
|
|
|
assert 'vlib/' in matches
|
2021-07-22 13:26:23 +03:00
|
|
|
assert 'thirdparty/' in matches
|
2021-06-30 08:30:18 +03:00
|
|
|
}
|
|
|
|
|
2022-09-21 19:45:43 +03:00
|
|
|
fn test_glob_can_be_used_with_multiple_patterns() {
|
2022-10-16 09:28:57 +03:00
|
|
|
os.chdir(@VMODROOT)!
|
|
|
|
matches := os.glob('*', 'cmd/tools/*')!
|
2021-06-30 08:30:18 +03:00
|
|
|
assert 'README.md' in matches
|
|
|
|
assert 'Makefile' in matches
|
|
|
|
$if !windows {
|
|
|
|
assert 'cmd/tools/test_if_v_test_system_works.v' in matches
|
|
|
|
}
|
|
|
|
$if windows {
|
|
|
|
assert 'test_if_v_test_system_works.v' in matches
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-21 19:45:43 +03:00
|
|
|
fn test_glob_star() {
|
2022-10-16 09:28:57 +03:00
|
|
|
os.chdir(@VMODROOT)!
|
|
|
|
matches := os.glob('*ake*')!
|
2021-06-30 08:30:18 +03:00
|
|
|
assert 'Makefile' in matches
|
|
|
|
assert 'make.bat' in matches
|
|
|
|
}
|
|
|
|
|
2022-09-21 19:45:43 +03:00
|
|
|
fn test_glob_not_found() {
|
2021-06-30 08:30:18 +03:00
|
|
|
os.glob('an_unknown_folder/*.v') or {
|
|
|
|
assert true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|