From decea1b1884564f5ed41aa5da3e58005938d8e2a Mon Sep 17 00:00:00 2001 From: Pepper Gray <111446242+peppergrayxyz@users.noreply.github.com> Date: Fri, 18 Oct 2024 09:57:26 +0200 Subject: [PATCH] v.pref: fix vsh_envbang_test.v to always use the local V executable (#22563) --- vlib/v/pref/vsh_envbang_test.v | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/vlib/v/pref/vsh_envbang_test.v b/vlib/v/pref/vsh_envbang_test.v index 91c04a14c4..c8f0d4668e 100644 --- a/vlib/v/pref/vsh_envbang_test.v +++ b/vlib/v/pref/vsh_envbang_test.v @@ -1,11 +1,22 @@ import os import rand -fn test_envbang_script_runs() { - env_location := '/usr/bin/env' +const vexe = @VEXE + +fn testsuite_begin() { $if windows { skip_test('windows does not support envbang lines') } + // Make sure, that we will be using the local v, instead of the globally installed one, + // for the rest of the tests here: + local_v_path := os.dir(vexe) + old_path := os.getenv('PATH') + os.setenv('PATH', '${local_v_path}:${old_path}', true) + println('Changed PATH: ${os.getenv('PATH')}') +} + +fn test_envbang_script_runs() { + env_location := '/usr/bin/env' if !os.exists(env_location) { skip_test('${env_location} does not exist') } @@ -18,14 +29,18 @@ fn test_envbang_script_runs() { os.write_file(rnd_vsh_script_path, "#!${env_location} v import os println('hello') +println('@VEXE: ${vexe}') println(os.args) ")! os.chmod(rnd_vsh_script_path, 0o700)! res := os.execute('${os.quoted_path(rnd_vsh_script_path)} abc 123 -option') assert res.exit_code == 0 lines := res.output.split_into_lines() + dump(lines) assert lines[0] == 'hello' - assert lines[1].ends_with(", 'abc', '123', '-option']") + assert lines[1].starts_with('@VEXE: ') + assert os.real_path(lines[1].all_after('@VEXE: ')) == os.real_path(vexe) + assert lines[2].ends_with(", 'abc', '123', '-option']") os.rm(rnd_vsh_script_path)! }