From ff4ba605167d47985da6efe43a69dd4f76a0421a Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Mon, 9 Oct 2023 13:55:46 +0200 Subject: [PATCH] fix --- .github/workflows/linux_ci.yml | 2 + cmd/tools/vcreate/vcreate_input_test.v | 103 +++++++++++++++++++++++++ cmd/tools/vcreate/vcreate_test.v | 83 -------------------- cmd/tools/vtest-self.v | 1 + 4 files changed, 106 insertions(+), 83 deletions(-) create mode 100644 cmd/tools/vcreate/vcreate_input_test.v diff --git a/.github/workflows/linux_ci.yml b/.github/workflows/linux_ci.yml index 362a2514540521..10c2c0b0cb0622 100644 --- a/.github/workflows/linux_ci.yml +++ b/.github/workflows/linux_ci.yml @@ -98,6 +98,8 @@ jobs: ./v2 -o v3 -usecache cmd/v ./v3 version ./v3 -o tetris -usecache examples/tetris/tetris.v + - name: Test module creation + run: ./v test cmd/tools/vcreate/vcreate_input_test.v - name: Test password input run: | ./v examples/password diff --git a/cmd/tools/vcreate/vcreate_input_test.v b/cmd/tools/vcreate/vcreate_input_test.v new file mode 100644 index 00000000000000..3ff03ad485dcbc --- /dev/null +++ b/cmd/tools/vcreate/vcreate_input_test.v @@ -0,0 +1,103 @@ +import os +import v.vmod + +// Note: the following uses `test_vcreate` and NOT `vcreate_input_test` deliberately, +// to both avoid confusions with the name of the current test itself, and to +// avoid clashes with the postfix `_test.v`, that V uses for its own test files. +// The test requires that `expect` is installed. +const test_path = os.join_path(os.vtmp_dir(), 'v', 'test_vcreate_input') + +fn prepare_test_path() ! { + os.rmdir_all(test_path) or {} + os.mkdir_all(test_path) or {} + os.chdir(test_path)! +} + +fn test_new_with_no_arg_input() { + $if windows { + eprintln('Input test for windows are not yet implemented.') + return + } + prepare_test_path()! + expect_tests_path := os.join_path(@VMODROOT, 'cmd', 'tools', 'vcreate', 'tests') + + // The expect script will create a new project in the temporary `test_path` directory. + project_name := 'my_project' + res := os.execute('${os.join_path(expect_tests_path, 'new_with_no_arg.expect')} ${@VMODROOT} ${project_name}') + if res.exit_code != 0 { + assert false, res.output + } + // Assert mod data set in `new_no_arg.expect`. + mod := vmod.decode(os.read_file(os.join_path(test_path, project_name, 'v.mod')) or { + assert false, 'Failed reading v.mod of ${project_name}' + return + }) or { + assert false, err.str() + return + } + assert mod.name == project_name + assert mod.description == 'My Awesome V Project.' + assert mod.version == '0.1.0' + assert mod.license == 'GPL' +} + +fn test_new_with_name_arg_input() { + $if windows { + eprintln('Input test for windows are not yet implemented.') + return + } + prepare_test_path()! + expect_tests_path := os.join_path(@VMODROOT, 'cmd', 'tools', 'vcreate', 'tests') + + // The expect script will create a new project in the temporary `test_path` directory. + project_name := 'my_other_project' + res := os.execute('${os.join_path(expect_tests_path, 'new_with_name_arg.expect')} ${@VMODROOT} ${project_name}') + if res.exit_code != 0 { + assert false, res.output + } + // Assert mod data set in `new_with_name_arg.expect`. + mod := vmod.decode(os.read_file(os.join_path(test_path, project_name, 'v.mod')) or { + assert false, 'Failed reading v.mod of ${project_name}' + return + }) or { + assert false, err.str() + return + } + assert mod.name == project_name + assert mod.description == '' + assert mod.version == '0.0.0' + assert mod.license == 'MIT' +} + +fn test_new_with_model_arg_input() { + $if windows { + eprintln('Input test for windows are not yet implemented.') + return + } + prepare_test_path()! + expect_tests_path := os.join_path(@VMODROOT, 'cmd', 'tools', 'vcreate', 'tests') + + // The expect script will create a new project in the temporary `test_path` directory. + project_name := 'my_lib' + model := 'lib' + res := os.execute('${os.join_path(expect_tests_path, 'new_with_model_arg.expect')} ${@VMODROOT} ${project_name} ${model}') + if res.exit_code != 0 { + assert false, res.output + } + // Assert mod data set in `new_with_model_arg.expect`. + mod := vmod.decode(os.read_file(os.join_path(test_path, project_name, 'v.mod')) or { + assert false, 'Failed reading v.mod of ${project_name}' + return + }) or { + assert false, err.str() + return + } + assert mod.name == project_name + assert mod.description == model + assert mod.version == '0.0.1' + assert mod.license == 'MIT' +} + +fn testsuite_end() { + os.rmdir_all(test_path) or {} +} diff --git a/cmd/tools/vcreate/vcreate_test.v b/cmd/tools/vcreate/vcreate_test.v index 6a5908f52c0229..dc3e3557e40567 100644 --- a/cmd/tools/vcreate/vcreate_test.v +++ b/cmd/tools/vcreate/vcreate_test.v @@ -1,5 +1,4 @@ import os -import v.vmod // Note: the following uses `test_vcreate` and NOT `vcreate_test` deliberately, // to both avoid confusions with the name of the current test itself, and to @@ -140,88 +139,6 @@ indent_style = tab assert os.read_file('.editorconfig')! == editor_config_content } -fn test_with_new_no_arg_input() { - $if windows { - eprintln('Input test for windows are not yet implemented.') - return - } - expect_tests_path := os.join_path(@VMODROOT, 'cmd', 'tools', 'vcreate', 'tests') - - // The expect script will create a new project in the temporary `test_path` directory. - project_name := 'my_project' - res := os.execute('${os.join_path(expect_tests_path, 'new_with_no_arg.expect')} ${@VMODROOT} ${project_name}') - if res.exit_code != 0 { - assert false, res.output - } - // Assert mod data set in `new_no_arg.expect`. - mod := vmod.decode(os.read_file(os.join_path(test_path, project_name, 'v.mod')) or { - assert false, 'Failed reading v.mod of ${project_name}' - return - }) or { - assert false, err.str() - return - } - assert mod.name == project_name - assert mod.description == 'My Awesome V Project.' - assert mod.version == '0.1.0' - assert mod.license == 'GPL' -} - -fn test_new_with_name_arg_input() { - $if windows { - eprintln('Input test for windows are not yet implemented.') - return - } - expect_tests_path := os.join_path(@VMODROOT, 'cmd', 'tools', 'vcreate', 'tests') - - // The expect script will create a new project in the temporary `test_path` directory. - project_name := 'my_other_project' - res := os.execute('${os.join_path(expect_tests_path, 'new_with_name_arg.expect')} ${@VMODROOT} ${project_name}') - if res.exit_code != 0 { - assert false, res.output - } - // Assert mod data set in `new_with_name_arg.expect`. - mod := vmod.decode(os.read_file(os.join_path(test_path, project_name, 'v.mod')) or { - assert false, 'Failed reading v.mod of ${project_name}' - return - }) or { - assert false, err.str() - return - } - assert mod.name == project_name - assert mod.description == '' - assert mod.version == '0.0.0' - assert mod.license == 'MIT' -} - -fn test_new_with_model_arg_input() { - $if windows { - eprintln('Input test for windows are not yet implemented.') - return - } - expect_tests_path := os.join_path(@VMODROOT, 'cmd', 'tools', 'vcreate', 'tests') - - // The expect script will create a new project in the temporary `test_path` directory. - project_name := 'my_lib' - model := 'lib' - res := os.execute('${os.join_path(expect_tests_path, 'new_with_model_arg.expect')} ${@VMODROOT} ${project_name} ${model}') - if res.exit_code != 0 { - assert false, res.output - } - // Assert mod data set in `new_with_model_arg.expect`. - mod := vmod.decode(os.read_file(os.join_path(test_path, project_name, 'v.mod')) or { - assert false, 'Failed reading v.mod of ${project_name}' - return - }) or { - assert false, err.str() - return - } - assert mod.name == project_name - assert mod.description == model - assert mod.version == '0.0.1' - assert mod.license == 'MIT' -} - fn testsuite_end() { os.rmdir_all(test_path) or {} } diff --git a/cmd/tools/vtest-self.v b/cmd/tools/vtest-self.v index 36a1a40b2c38ec..2aed5c5573271b 100644 --- a/cmd/tools/vtest-self.v +++ b/cmd/tools/vtest-self.v @@ -85,6 +85,7 @@ const ( ] skip_test_files = [ 'do_not_remove', + 'cmd/tools/vcreate/vcreate_input_test.v', // it's not given that expect is installed on all systems. 'cmd/tools/vdoc/html_tag_escape_test.v', // can't locate local module: markdown 'cmd/tools/vdoc/tests/vdoc_file_test.v', // fails on Windows; order of output is not as expected 'vlib/context/deadline_test.v', // sometimes blocks