Skip to content

Commit

Permalink
vcreate: test new module creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Oct 7, 2023
1 parent 8023e25 commit c36da90
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cmd/tools/vcreate/new_no_arg.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/expect

set timeout 10
# Pass v_root as arg, since we chdir into a temp directoy during testing and create a project there.
set v_root [lindex $argv 0]
set project_name [lindex $argv 1]

proc assert {expect_ {send_ ""}} {
expect $expect_ {
if {$send_ != ""} {
send $send_
}
} timeout {
puts "!= $expect_"
exit 1
}
}

spawn $v_root/v run $v_root/cmd/tools/vcreate/ new

assert "Input your project name: " "$project_name\r"
assert "Input your project description: " "My awesome V project.\r"
assert "Input your project version: (0.0.0) " "0.1.0\r"
assert "Input your project license: (MIT) " "GPL\r"
assert "Initialising ..."
assert "Complete!"

expect eof
26 changes: 26 additions & 0 deletions cmd/tools/vcreate/vcreate_test.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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 @@ -139,6 +140,31 @@ indent_style = tab
assert os.read_file('.editorconfig')! == editor_config_content
}

fn test_input() {
$if windows {
eprintln('Input test for windows are not yet implemented.')
return
}
expect_path := os.join_path(@VMODROOT, 'cmd', 'tools', 'vcreate')
project_name := 'my_project'
new_no_arg := os.execute(os.join_path(expect_path, 'new_no_arg.expect ${@VMODROOT} ${project_name}'))
if new_no_arg.exit_code != 0 {
assert false, new_no_arg.output
}
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 module data set in ./new_no_arg.expect
assert mod.name == 'my_project'
assert mod.description == 'My awesome V project.'
assert mod.version == '0.1.0'
assert mod.license == 'GPL'
}

fn testsuite_end() {
os.rmdir_all(test_path) or {}
}

0 comments on commit c36da90

Please sign in to comment.