1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

ci: fix v test-self failures related to cmd/tools/vcreate_test.v

This commit is contained in:
Delyan Angelov 2022-12-21 21:13:06 +02:00
parent 68501677e3
commit 46ced75184
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 28 additions and 7 deletions

View File

@ -2,11 +2,20 @@
// Use of this source code is governed by an MIT license that can be found in the LICENSE file. // Use of this source code is governed by an MIT license that can be found in the LICENSE file.
module main module main
// This module follows a similar convention to Rust: `init` makes the import os
// Note: this program follows a similar convention to Rust: `init` makes the
// structure of the program in the _current_ directory, while `new` // structure of the program in the _current_ directory, while `new`
// makes the program structure in a _sub_ directory. Besides that, the // makes the program structure in a _sub_ directory. Besides that, the
// functionality is essentially the same. // functionality is essentially the same.
import os
// Note: here are the currently supported invokations so far:
// 1) `v init` -> create a new project in the current folder
// 2) `v new abc` -> create a new project in the new folder `abc`, by default a "hello world" project.
// 3) `v new abcd web` -> create a new project in the new folder `abcd`, using the vweb template.
// 4) `v new abcde gg` -> create a new project in the new folder `abcde`, using the gg template.
// Note: run `v cmd/tools/vcreate_test.v` after changes to this program, to avoid regressions.
struct Create { struct Create {
mut: mut:
@ -53,9 +62,13 @@ fn vmod_content(c Create) string {
} }
fn new_project_content() string { fn new_project_content() string {
if os.args.len == 2 && os.args[1] == 'init' {
return main_content()
}
if os.args.len == 3 { if os.args.len == 3 {
return main_content() return main_content()
} else if os.args.len == 4 { }
if os.args.len == 4 {
kind := os.args.last() kind := os.args.last()
return match kind { return match kind {
'web' { 'web' {

View File

@ -1,11 +1,19 @@
import os import os
const test_path = os.join_path(os.vtmp_dir(), 'v', 'vcreate_test') // 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
// avoid clashes with the postfix `_test.v`, that V uses for its own test files.
const test_path = os.join_path(os.vtmp_dir(), 'v', 'test_vcreate')
fn init_and_check() ! { fn init_and_check() ! {
os.chdir(test_path)!
os.execute_or_exit('${os.quoted_path(@VEXE)} init') os.execute_or_exit('${os.quoted_path(@VEXE)} init')
assert os.read_file('vcreate_test.v')! == [ x := os.execute_or_exit('${os.quoted_path(@VEXE)} run .')
assert x.exit_code == 0
assert x.output.trim_space() == 'Hello World!'
assert os.read_file('test_vcreate.v')! == [
'module main\n', 'module main\n',
'fn main() {', 'fn main() {',
" println('Hello World!')", " println('Hello World!')",
@ -15,7 +23,7 @@ fn init_and_check() ! {
assert os.read_file('v.mod')! == [ assert os.read_file('v.mod')! == [
'Module {', 'Module {',
" name: 'vcreate_test'", " name: 'test_vcreate'",
" description: ''", " description: ''",
" version: ''", " version: ''",
" license: ''", " license: ''",
@ -27,7 +35,7 @@ fn init_and_check() ! {
assert os.read_file('.gitignore')! == [ assert os.read_file('.gitignore')! == [
'# Binaries for programs and plugins', '# Binaries for programs and plugins',
'main', 'main',
'vcreate_test', 'test_vcreate',
'*.exe', '*.exe',
'*.exe~', '*.exe~',
'*.so', '*.so',