@@ -217,6 +217,47 @@ fn test_macos_v3_relevant_command_selects_user_compilation_and_tests() {
217217 }
218218}
219219
220+ fn test_macos_v3_compiler_bootstrap_is_detected_from_any_cwd () {
221+ // Repo-relative and absolute spellings are recognized directly.
222+ assert is_macos_v3_compiler_bootstrap ('vlib/v3/v3.v' )
223+ assert is_macos_v3_compiler_bootstrap ('/home/user/v/vlib/v3/v3.v' )
224+ // Non-bootstrap targets stay on the V3 path.
225+ assert ! is_macos_v3_compiler_bootstrap ('main.v' )
226+ assert ! is_macos_v3_compiler_bootstrap ('cmd/v' )
227+ assert ! is_macos_v3_compiler_bootstrap ('some/other/place/v3.v' )
228+
229+ // A bare `v3.v` invoked from inside vlib/v3 must resolve to the bootstrap so
230+ // it builds with the compatibility compiler instead of the embedded V3 driver.
231+ // Use an isolated <tmp>/vlib/v3/v3.v so this exercises the real-path
232+ // resolution unconditionally, independent of where this test file lives.
233+ root := os.join_path (os.real_path (os.vtmp_dir ()), 'macos_v3_bootstrap_${os .getpid ()}' )
234+ v3_dir := os.join_path (root, 'vlib' , 'v3' )
235+ other_dir := os.join_path (root, 'elsewhere' )
236+ os.rmdir_all (root) or {}
237+ os.mkdir_all (v3_ dir) or { panic (err) }
238+ os.mkdir_all (other_dir) or { panic (err) }
239+ defer {
240+ os.rmdir_all (root) or {}
241+ }
242+ os.write_file (os.join_path (v3_ dir, 'v3.v' ), 'module main\n ' ) or { panic (err) }
243+ os.write_file (os.join_path (other_dir, 'v3.v' ), 'module main\n ' ) or { panic (err) }
244+
245+ saved := os.getwd ()
246+ defer {
247+ os.chdir (saved) or {}
248+ }
249+ os.chdir (v3_ dir) or { panic (err) }
250+ bare := is_macos_v3_compiler_bootstrap ('v3.v' )
251+ dotted := is_macos_v3_compiler_bootstrap ('./v3.v' )
252+ // A bare `v3.v` that is not under vlib/v3 must stay on the V3 path.
253+ os.chdir (other_dir) or { panic (err) }
254+ non_bootstrap := is_macos_v3_compiler_bootstrap ('v3.v' )
255+ os.chdir (saved) or {}
256+ assert bare
257+ assert dotted
258+ assert ! non_bootstrap
259+ }
260+
220261fn test_macos_v3_dispatch_allows_the_implicit_gc_default () {
221262 $if macos {
222263 implicit_gc , _ := pref.parse_args_and_show_errors ([], ['' , 'main.v' ], false )
0 commit comments