Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Oct 9, 2023
1 parent 0f4f951 commit ff4ba60
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 83 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/linux_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
103 changes: 103 additions & 0 deletions cmd/tools/vcreate/vcreate_input_test.v
Original file line number Diff line number Diff line change
@@ -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 {}
}
83 changes: 0 additions & 83 deletions cmd/tools/vcreate/vcreate_test.v
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {}
}
1 change: 1 addition & 0 deletions cmd/tools/vtest-self.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff4ba60

Please sign in to comment.