From c36da90e6a162cec9ef8e76e5a78ad37fa82fd45 Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Fri, 6 Oct 2023 02:35:52 +0200 Subject: [PATCH] vcreate: test new module creation --- cmd/tools/vcreate/new_no_arg.expect | 28 ++++++++++++++++++++++++++++ cmd/tools/vcreate/vcreate_test.v | 26 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100755 cmd/tools/vcreate/new_no_arg.expect diff --git a/cmd/tools/vcreate/new_no_arg.expect b/cmd/tools/vcreate/new_no_arg.expect new file mode 100755 index 00000000000000..928b838eb875e3 --- /dev/null +++ b/cmd/tools/vcreate/new_no_arg.expect @@ -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 diff --git a/cmd/tools/vcreate/vcreate_test.v b/cmd/tools/vcreate/vcreate_test.v index dc3e3557e40567..67902c81c4ffdb 100644 --- a/cmd/tools/vcreate/vcreate_test.v +++ b/cmd/tools/vcreate/vcreate_test.v @@ -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 @@ -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 {} }