tools.vcreate: rework cli arg handling to extend scaffolding and fix issues (#19889)

This commit is contained in:
Turiiya 2023-11-16 14:40:23 +01:00 committed by GitHub
parent 9308bcd48a
commit e9258c2a08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 237 additions and 139 deletions

View file

@ -24,11 +24,11 @@ fn testsuite_end() {
fn init_and_check() ! {
os.chdir(test_path)!
// Keep track of the last modified time of the main file to ensure it is not modifed if it already exists.
// Keep track of the last modified time of the main file to ensure it is not modified if it already exists.
main_exists := os.exists('src/main.v')
main_last_modified := if main_exists { os.file_last_mod_unix('src/main.v') } else { 0 }
// Initilize project.
// Initialize project.
os.execute_or_exit('${expect_exe} ${os.join_path(expect_tests_path, 'init.expect')} ${vroot}')
x := os.execute_or_exit('${vexe} run .')
@ -147,13 +147,13 @@ indent_style = tab
prepare_test_path()!
os.write_file('.gitattributes', git_attributes_content)!
os.write_file('.editorconfig', editor_config_content)!
os.execute_or_exit('${expect_exe} ${os.join_path(expect_tests_path, 'init.expect')} ${vroot}')
res := os.execute_or_exit('${expect_exe} ${os.join_path(expect_tests_path, 'init.expect')} ${vroot}')
assert res.output.contains('Created binary (application) project `${test_project_dir_name}`')
assert os.read_file('.gitattributes')! == git_attributes_content
assert os.read_file('.editorconfig')! == editor_config_content
}
fn test_v_init_in_dir_with_invalid_mod_name() {
fn test_v_init_in_dir_with_invalid_mod_name_input() {
// A project with a directory name with hyphens, which is invalid for a module name.
dir_name_with_invalid_mod_name := 'my-proj'
corrected_mod_name := 'my_proj'
@ -168,3 +168,21 @@ fn test_v_init_in_dir_with_invalid_mod_name() {
}
assert mod.name == corrected_mod_name
}
fn test_v_init_with_model_arg_input() {
prepare_test_path()!
model := '--lib'
res := os.execute_or_exit('${expect_exe} ${os.join_path(expect_tests_path, 'init_with_model_arg.expect')} ${vroot} ${model}')
assert res.output.contains('Created library project `${test_project_dir_name}`'), res.output
project_path := os.join_path(test_path)
mod := vmod.from_file(os.join_path(project_path, 'v.mod')) or {
assert false, err.str()
return
}
assert mod.name == test_project_dir_name
assert mod.description == 'My Awesome V Application.'
assert mod.version == '0.0.1'
assert mod.license == 'MIT'
// Assert existence of a model-specific file.
assert os.exists(os.join_path(project_path, 'tests', 'square_test.v'))
}