From 53ac41ff061f177105cd4fea1ca7c37e92b67d93 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 10 Jun 2024 14:06:41 +0300 Subject: [PATCH] ci: move the test cases in unknown_options_test.v to pref_test.v, to minimise false positives (both compiled and ran examples/hello_world.v in parallel) --- vlib/v/pref/pref_test.v | 38 +++++++++++++++++++++++++++++ vlib/v/pref/unknown_options_test.v | 39 ------------------------------ 2 files changed, 38 insertions(+), 39 deletions(-) delete mode 100644 vlib/v/pref/unknown_options_test.v diff --git a/vlib/v/pref/pref_test.v b/vlib/v/pref/pref_test.v index a859420dc1..1c59ffe811 100644 --- a/vlib/v/pref/pref_test.v +++ b/vlib/v/pref/pref_test.v @@ -63,3 +63,41 @@ fn test_v_cmds_and_flags() { no_bm_files_res := os.execute('${vexe} build-module') assert no_bm_files_res.output.trim_space() == 'v build-module: no module specified' } + +const tfile = os.join_path(os.vtmp_dir(), 'unknown_options_output.c') + +fn test_unknown_option_flags_no_run() { + os.chdir(os.dir(@VEXE))! + os.rm(tfile) or {} + + res1 := os.execute('${os.quoted_path(@VEXE)} -o ${os.quoted_path(tfile)} examples/hello_world.v --an-unknown-option') + assert res1.exit_code == 1, res1.output + assert res1.output.starts_with('Unknown argument') + assert res1.output.contains('--an-unknown-option') + assert !os.exists(tfile) + + res2 := os.execute('${os.quoted_path(@VEXE)} -o ${os.quoted_path(tfile)} --an-unknown-option examples/hello_world.v') + assert res2.exit_code == 1, res2.output + assert res2.output.starts_with('Unknown argument') + assert res2.output.contains('--an-unknown-option') + assert !os.exists(tfile) +} + +fn test_unknown_option_flags_with_run() { + res_run_o := os.execute('${os.quoted_path(@VEXE)} -o ${os.quoted_path(tfile)} run examples/hello_world.v --an-unknown-option') + assert res_run_o.exit_code == 0, res_run_o.output + assert res_run_o.output == '' // because of -o, there should not be an actual run, since compilation stopped after generating the .c file + assert os.exists(tfile) + os.rm(tfile) or {} + + res_run_no_o_unknown_before_run := os.execute('${os.quoted_path(@VEXE)} --an-unknown-option run examples/hello_world.v ') + assert res_run_no_o_unknown_before_run.exit_code == 1, res_run_no_o_unknown_before_run.output + assert res_run_no_o_unknown_before_run.output.starts_with('Unknown argument') + assert res_run_no_o_unknown_before_run.output.contains('--an-unknown-option') + assert !os.exists(tfile) + + res_run_no_o := os.execute('${os.quoted_path(@VEXE)} run examples/hello_world.v --an-unknown-option') + assert res_run_no_o.exit_code == 0, res_run_no_o.output + assert res_run_no_o.output.trim_space() == 'Hello, World!' + assert !os.exists(tfile) +} diff --git a/vlib/v/pref/unknown_options_test.v b/vlib/v/pref/unknown_options_test.v deleted file mode 100644 index 11dee7c289..0000000000 --- a/vlib/v/pref/unknown_options_test.v +++ /dev/null @@ -1,39 +0,0 @@ -import os - -const tfile = os.join_path(os.vtmp_dir(), 'unknown_options_output.c') - -fn test_unknown_option_flags_no_run() { - os.chdir(os.dir(@VEXE))! - os.rm(tfile) or {} - - res1 := os.execute('${os.quoted_path(@VEXE)} -o ${os.quoted_path(tfile)} examples/hello_world.v --an-unknown-option') - assert res1.exit_code == 1, res1.output - assert res1.output.starts_with('Unknown argument') - assert res1.output.contains('--an-unknown-option') - assert !os.exists(tfile) - - res2 := os.execute('${os.quoted_path(@VEXE)} -o ${os.quoted_path(tfile)} --an-unknown-option examples/hello_world.v') - assert res2.exit_code == 1, res2.output - assert res2.output.starts_with('Unknown argument') - assert res2.output.contains('--an-unknown-option') - assert !os.exists(tfile) -} - -fn test_unknown_option_flags_with_run() { - res_run_o := os.execute('${os.quoted_path(@VEXE)} -o ${os.quoted_path(tfile)} run examples/hello_world.v --an-unknown-option') - assert res_run_o.exit_code == 0, res_run_o.output - assert res_run_o.output == '' // because of -o, there should not be an actual run, since compilation stopped after generating the .c file - assert os.exists(tfile) - os.rm(tfile) or {} - - res_run_no_o_unknown_before_run := os.execute('${os.quoted_path(@VEXE)} --an-unknown-option run examples/hello_world.v ') - assert res_run_no_o_unknown_before_run.exit_code == 1, res_run_no_o_unknown_before_run.output - assert res_run_no_o_unknown_before_run.output.starts_with('Unknown argument') - assert res_run_no_o_unknown_before_run.output.contains('--an-unknown-option') - assert !os.exists(tfile) - - res_run_no_o := os.execute('${os.quoted_path(@VEXE)} run examples/hello_world.v --an-unknown-option') - assert res_run_no_o.exit_code == 0, res_run_no_o.output - assert res_run_no_o.output.trim_space() == 'Hello, World!' - assert !os.exists(tfile) -}