@@ -23,6 +23,10 @@ let test_create_search_path _ =
23
23
~cmp: SearchPath. equal
24
24
(SearchPath. Subdirectory { root; subdirectory = " subdirectory" })
25
25
(SearchPath. create (Path. show root ^ " $subdirectory" ));
26
+ assert_equal
27
+ ~cmp: SearchPath. equal
28
+ (SearchPath. Submodule { root; submodule = " submodule.py" })
29
+ (SearchPath. create (Path. show root ^ " $submodule.py" ));
26
30
assert_raises (Failure " Unable to create search path from too$many$levels" ) (fun () ->
27
31
SearchPath. create " too$many$levels" )
28
32
@@ -38,6 +42,8 @@ let test_show_search_path _ =
38
42
assert_round_trip (SearchPath. Subdirectory { root = ! " /foo" ; subdirectory = " bar" });
39
43
assert_round_trip (SearchPath. Subdirectory { root = ! " /foo/bar" ; subdirectory = " baz" });
40
44
assert_round_trip (SearchPath. Subdirectory { root = ! " /foo" ; subdirectory = " bar/baz" });
45
+ assert_round_trip (SearchPath. Submodule { root = ! " /foo" ; submodule = " bar.py" });
46
+ assert_round_trip (SearchPath. Submodule { root = ! " /foo" ; submodule = " bar/baz.py" });
41
47
()
42
48
43
49
@@ -46,11 +52,12 @@ let test_normalize context =
46
52
let bad_root = " nonexist/directory" in
47
53
let good_subroot = good_root ^ " /subroot" in
48
54
Sys_utils. mkdir_no_fail good_subroot;
49
- let create_input ?subdirectory root =
55
+ let create_input ?subdirectory ? submodule root =
50
56
let search_path =
51
- match subdirectory with
52
- | None -> SearchPath. Root ! root
53
- | Some subdirectory -> SearchPath. Subdirectory { root = ! root; subdirectory }
57
+ match subdirectory, submodule with
58
+ | Some subdirectory , _ -> SearchPath. Subdirectory { root = ! root; subdirectory }
59
+ | _ , Some submodule -> SearchPath. Submodule { root = ! root; submodule }
60
+ | _ -> SearchPath. Root ! root
54
61
in
55
62
SearchPath. show search_path
56
63
in
@@ -90,6 +97,7 @@ let test_normalize context =
90
97
assert_success ~normalize: false ~expected: true (create_input ~subdirectory: " subroot" good_root);
91
98
assert_success ~normalize: false ~expected: true (create_input ~subdirectory: " nosubroot" good_root);
92
99
assert_success ~normalize: false ~expected: true (create_input ~subdirectory: " subroot" bad_root);
100
+ assert_success ~normalize: false ~expected: true (create_input ~submodule: " subroot" bad_root);
93
101
94
102
(* Normalized creation depends on filesystem state. *)
95
103
assert_success ~normalize: true ~expected: true (create_input good_root);
@@ -98,6 +106,8 @@ let test_normalize context =
98
106
assert_success ~normalize: true ~expected: true (create_input ~subdirectory: " subroot" good_root);
99
107
assert_success ~normalize: true ~expected: false (create_input ~subdirectory: " nosubroot" good_root);
100
108
assert_success ~normalize: true ~expected: false (create_input ~subdirectory: " subroot" bad_root);
109
+ assert_success ~normalize: true ~expected: true (create_input ~submodule: " subroot" good_root);
110
+ assert_success ~normalize: true ~expected: false (create_input ~submodule: " subroot" bad_root);
101
111
102
112
()
103
113
@@ -116,6 +126,7 @@ let test_search_for_path context =
116
126
SearchPath. Subdirectory
117
127
{ root = Path. create_relative ~root ~relative: " b" ; subdirectory = " c" };
118
128
SearchPath. Subdirectory { root; subdirectory = " b" };
129
+ SearchPath. Submodule { root; submodule = " b.py" };
119
130
]
120
131
in
121
132
assert_path
@@ -129,7 +140,8 @@ let test_search_for_path context =
129
140
assert_path
130
141
~search_paths
131
142
~path: (Path. create_relative ~root ~relative: " b/other/file.py" )
132
- ~expected: " b/other/file.py"
143
+ ~expected: " b/other/file.py" ;
144
+ assert_path ~search_paths ~path: (Path. create_relative ~root ~relative: " b.py" ) ~expected: " b.py"
133
145
134
146
135
147
let () =
0 commit comments