Skip to content

Commit b99fa5b

Browse files
committed
Handle alternate test source/header paths
Make tests resilient to differing repo layouts by adding fallback path checks. In projects_test.v, get_source_dir now checks the new modules/tests/sources/<dir> layout, special-cases psc_deps, and falls back to modules/tests/<dir> before failing. In selective_headers_loading_test.v, header_dir resolution tries modules/tests/sources/psc_deps first then modules/tests/psc_deps, validating that Form.psc exists. These changes improve backward compatibility with submodule or layout changes.
1 parent c095dbd commit b99fa5b

2 files changed

Lines changed: 32 additions & 8 deletions

File tree

modules/tests/projects_test.v

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,28 @@ fn get_prefs(input_dir string, header_dirs []string, output_dir string) pref.Pre
1717
}
1818

1919
fn get_source_dir(dir_name string, required_file_name string) string {
20-
path := os.abs_path(os.join_path("modules", "tests", "sources", dir_name))
21-
required_file := os.join_path(path, required_file_name)
20+
// First try with the new submodule structure
21+
mut path := os.abs_path(os.join_path("modules", "tests", "sources", dir_name))
22+
mut required_file := os.join_path(path, required_file_name)
2223

24+
// If not found, try original structure (for backward compatibility)
2325
if !os.is_dir(path) || !os.is_file(required_file) {
26+
// For psc_deps specifically, check if it exists directly under sources
27+
if dir_name == "psc_deps" {
28+
path = os.abs_path(os.join_path("modules", "tests", "sources", "psc_deps"))
29+
required_file = os.join_path(path, required_file_name)
30+
if os.is_dir(path) && os.is_file(required_file) {
31+
return path
32+
}
33+
}
34+
35+
// Check the old path as a fallback
36+
path = os.abs_path(os.join_path("modules", "tests", dir_name))
37+
required_file = os.join_path(path, required_file_name)
38+
if os.is_dir(path) && os.is_file(required_file) {
39+
return path
40+
}
41+
2442
assert false, "[get_source_dir] invalid directory ${path} or missing required file ${required_file}"
2543
}
2644

modules/tests/selective_headers_loading_test.v

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@ const placeholder_objects = ["actor", "textureset", "keyword", "magiceffect",
1313
fn test_selective_headers_loading() {
1414
src_file := os.real_path(os.join_path("modules", "tests", "psc", "TestSelectiveLoading.psc"))
1515
output_dir := os.real_path(os.join_path("test-files", "compiled"))
16-
header_dir := os.real_path(os.join_path("modules", "tests", "sources", "psc_deps"))
17-
16+
17+
// Try multiple possible locations for the header directory
18+
mut header_dir := os.real_path(os.join_path("modules", "tests", "sources", "psc_deps"))
19+
20+
// If not found, try the original location
21+
if !os.is_dir(header_dir) || !os.is_file(os.join_path(header_dir, "Form.psc")) {
22+
header_dir = os.real_path(os.join_path("modules", "tests", "psc_deps"))
23+
if !os.is_dir(header_dir) || !os.is_file(os.join_path(header_dir, "Form.psc")) {
24+
assert false, "invalid header dir ${header_dir}"
25+
}
26+
}
27+
1828
if !os.is_file(src_file) {
1929
assert false, "invalid input file ${src_file}"
2030
}
2131

22-
if !os.is_dir(header_dir) || !os.is_file(os.join_path(header_dir, "Form.psc")) {
23-
assert false, "invalid header dir ${header_dir}"
24-
}
25-
2632
if !os.is_dir(output_dir) {
2733
os.mkdir(output_dir, os.MkdirParams{}) or { assert false, "failed to create output folder" }
2834
}

0 commit comments

Comments
 (0)