@@ -14,6 +14,18 @@ fn testsuite_end() {
1414 os.rmdir_all (test_path) or {}
1515}
1616
17+ fn execute_in_dir (dir string , cmd string ) os.Result {
18+ old_dir := os.getwd ()
19+ os.chdir (dir) or { return os.Result{
20+ exit_code: - 1
21+ output: 'failed to chdir: ${err} '
22+ } }
23+ defer {
24+ os.chdir (old_dir) or {}
25+ }
26+ return os.execute (cmd)
27+ }
28+
1729fn test_link_and_unlink_current_project () {
1830 module_name := 'author.coollib'
1931 project_path := os.join_path (test_path, 'project' )
@@ -28,7 +40,7 @@ fn test_link_and_unlink_current_project() {
2840 }
2941 link_path := os.join_path (test_path, 'author' , 'coollib' )
3042
31- link_res := os. execute ( 'cd ${os.quoted_path( project_subdir)} && ${vexe} link' )
43+ link_res := execute_in_dir ( project_subdir, ' ${vexe} link' )
3244 if link_res.exit_code != 0 && is_symlink_privilege_error (link_res.output) {
3345 eprintln ('Skipping symlink test due to missing privileges.' )
3446 return
@@ -38,12 +50,12 @@ fn test_link_and_unlink_current_project() {
3850 assert os.real_path (link_path) == os.real_path (project_path)
3951 assert link_res.output.contains ('Linked `${module_name} `' ), link_res.output
4052
41- link_again_res := os. execute ( 'cd ${os.quoted_path( project_path)} && ${vexe} link' )
53+ link_again_res := execute_in_dir ( project_path, ' ${vexe} link' )
4254 assert link_again_res.exit_code == 0 , link_again_res.output
4355 assert link_again_res.output.contains ('already linked' )
4456 || link_again_res.output.contains ('already available' ), link_again_res.output
4557
46- unlink_res := os. execute ( 'cd ${os.quoted_path( project_subdir)} && ${vexe} unlink' )
58+ unlink_res := execute_in_dir ( project_subdir, ' ${vexe} unlink' )
4759 assert unlink_res.exit_code == 0 , unlink_res.output
4860 assert ! os.exists (link_path) && ! os.is_link (link_path)
4961 assert ! os.exists (os.join_path (test_path, 'author' ))
@@ -56,7 +68,7 @@ fn test_link_without_vmod() {
5668 assert false , err.msg ()
5769 return
5870 }
59- res := os. execute ( 'cd ${os.quoted_path( path)} && ${vexe} link' )
71+ res := execute_in_dir ( path, ' ${vexe} link' )
6072 assert res.exit_code == 1 , res.output
6173 assert res.output.contains ('no `v.mod` file found' ), res.output
6274}
0 commit comments