2021-06-16 19:57:51 +03:00
|
|
|
import os
|
|
|
|
|
2022-12-21 22:13:06 +03:00
|
|
|
// 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')
|
2021-06-16 19:57:51 +03:00
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
fn init_and_check() ! {
|
2022-12-21 22:13:06 +03:00
|
|
|
os.chdir(test_path)!
|
2023-02-20 13:54:38 +03:00
|
|
|
|
|
|
|
// if main file already exist we should not tamper it
|
|
|
|
mut main_last_modified_time := i64(0)
|
|
|
|
is_main_file_preexisting := os.exists('src/main.v')
|
|
|
|
if is_main_file_preexisting == true {
|
|
|
|
main_last_modified_time = os.file_last_mod_unix('src/main.v')
|
|
|
|
}
|
2022-01-22 22:13:16 +03:00
|
|
|
os.execute_or_exit('${os.quoted_path(@VEXE)} init')
|
2021-06-16 19:57:51 +03:00
|
|
|
|
2022-12-21 22:13:06 +03:00
|
|
|
x := os.execute_or_exit('${os.quoted_path(@VEXE)} run .')
|
|
|
|
assert x.exit_code == 0
|
|
|
|
assert x.output.trim_space() == 'Hello World!'
|
|
|
|
|
2023-02-20 13:54:38 +03:00
|
|
|
if is_main_file_preexisting == true {
|
|
|
|
assert main_last_modified_time == os.file_last_mod_unix('src/main.v')
|
|
|
|
} else {
|
|
|
|
assert os.read_file('src/main.v')! == [
|
|
|
|
'module main\n',
|
|
|
|
'fn main() {',
|
|
|
|
" println('Hello World!')",
|
|
|
|
'}',
|
|
|
|
'',
|
|
|
|
].join_lines()
|
|
|
|
}
|
2021-06-16 19:57:51 +03:00
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
assert os.read_file('v.mod')! == [
|
2021-06-16 19:57:51 +03:00
|
|
|
'Module {',
|
2022-12-21 22:13:06 +03:00
|
|
|
" name: 'test_vcreate'",
|
2021-06-16 19:57:51 +03:00
|
|
|
" description: ''",
|
|
|
|
" version: ''",
|
|
|
|
" license: ''",
|
|
|
|
' dependencies: []',
|
|
|
|
'}',
|
|
|
|
'',
|
2021-12-17 17:11:19 +03:00
|
|
|
].join_lines()
|
2021-06-16 19:57:51 +03:00
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
assert os.read_file('.gitignore')! == [
|
2021-06-16 19:57:51 +03:00
|
|
|
'# Binaries for programs and plugins',
|
|
|
|
'main',
|
2022-12-21 22:13:06 +03:00
|
|
|
'test_vcreate',
|
2021-06-16 19:57:51 +03:00
|
|
|
'*.exe',
|
|
|
|
'*.exe~',
|
|
|
|
'*.so',
|
|
|
|
'*.dylib',
|
|
|
|
'*.dll',
|
2022-11-02 21:41:12 +03:00
|
|
|
'',
|
2022-11-20 15:43:33 +03:00
|
|
|
'# Ignore binary output folders',
|
|
|
|
'bin/',
|
|
|
|
'',
|
2022-11-02 21:41:12 +03:00
|
|
|
'# Ignore common editor/system specific metadata',
|
|
|
|
'.DS_Store',
|
|
|
|
'.idea/',
|
|
|
|
'.vscode/',
|
|
|
|
'*.iml',
|
2021-06-16 19:57:51 +03:00
|
|
|
'',
|
2023-01-09 09:37:46 +03:00
|
|
|
'# ENV',
|
|
|
|
'.env',
|
|
|
|
'',
|
|
|
|
'# vweb and database',
|
|
|
|
'*.db',
|
|
|
|
'*.js',
|
|
|
|
'',
|
2021-12-17 17:11:19 +03:00
|
|
|
].join_lines()
|
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
assert os.read_file('.gitattributes')! == [
|
2022-11-02 21:41:12 +03:00
|
|
|
'* text=auto eol=lf',
|
|
|
|
'*.bat eol=crlf',
|
|
|
|
'',
|
|
|
|
'**/*.v linguist-language=V',
|
|
|
|
'**/*.vv linguist-language=V',
|
|
|
|
'**/*.vsh linguist-language=V',
|
|
|
|
'**/v.mod linguist-language=V',
|
2021-12-17 17:11:19 +03:00
|
|
|
'',
|
|
|
|
].join_lines()
|
2022-01-20 14:01:30 +03:00
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
assert os.read_file('.editorconfig')! == [
|
2022-01-20 14:01:30 +03:00
|
|
|
'[*]',
|
|
|
|
'charset = utf-8',
|
|
|
|
'end_of_line = lf',
|
|
|
|
'insert_final_newline = true',
|
|
|
|
'trim_trailing_whitespace = true',
|
|
|
|
'',
|
|
|
|
'[*.v]',
|
|
|
|
'indent_style = tab',
|
|
|
|
'',
|
|
|
|
].join_lines()
|
2021-06-16 19:57:51 +03:00
|
|
|
}
|
2021-06-19 21:36:12 +03:00
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
fn prepare_test_path() ! {
|
2022-09-16 04:56:19 +03:00
|
|
|
os.rmdir_all(test_path) or {}
|
|
|
|
os.mkdir_all(test_path) or {}
|
2022-10-16 09:28:57 +03:00
|
|
|
os.chdir(test_path)!
|
2022-09-16 04:56:19 +03:00
|
|
|
}
|
2021-06-19 21:36:12 +03:00
|
|
|
|
2022-09-21 19:45:43 +03:00
|
|
|
fn test_v_init() {
|
2022-10-16 09:28:57 +03:00
|
|
|
prepare_test_path()!
|
|
|
|
init_and_check()!
|
2021-06-19 21:36:12 +03:00
|
|
|
}
|
|
|
|
|
2022-09-21 19:45:43 +03:00
|
|
|
fn test_v_init_in_git_dir() {
|
2022-10-16 09:28:57 +03:00
|
|
|
prepare_test_path()!
|
2021-07-20 14:04:35 +03:00
|
|
|
os.execute_or_exit('git init .')
|
2022-10-16 09:28:57 +03:00
|
|
|
init_and_check()!
|
2021-06-19 21:36:12 +03:00
|
|
|
}
|
|
|
|
|
2022-09-21 19:45:43 +03:00
|
|
|
fn test_v_init_no_overwrite_gitignore() {
|
2022-10-16 09:28:57 +03:00
|
|
|
prepare_test_path()!
|
|
|
|
os.write_file('.gitignore', 'blah')!
|
2022-01-22 22:13:16 +03:00
|
|
|
os.execute_or_exit('${os.quoted_path(@VEXE)} init')
|
2022-10-16 09:28:57 +03:00
|
|
|
assert os.read_file('.gitignore')! == 'blah'
|
2021-06-19 21:36:12 +03:00
|
|
|
}
|
2022-01-20 14:01:30 +03:00
|
|
|
|
2022-09-21 19:45:43 +03:00
|
|
|
fn test_v_init_no_overwrite_gitattributes_and_editorconfig() {
|
2022-01-20 14:01:30 +03:00
|
|
|
git_attributes_content := '*.v linguist-language=V text=auto eol=lf'
|
|
|
|
editor_config_content := '[*]
|
|
|
|
charset = utf-8
|
|
|
|
end_of_line = lf
|
|
|
|
insert_final_newline = true
|
|
|
|
trim_trailing_whitespace = true
|
|
|
|
|
|
|
|
[*.v]
|
|
|
|
indent_style = tab
|
|
|
|
'
|
2022-10-16 09:28:57 +03:00
|
|
|
prepare_test_path()!
|
|
|
|
os.write_file('.gitattributes', git_attributes_content)!
|
|
|
|
os.write_file('.editorconfig', editor_config_content)!
|
2022-01-22 22:13:16 +03:00
|
|
|
os.execute_or_exit('${os.quoted_path(@VEXE)} init')
|
2022-01-20 14:01:30 +03:00
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
assert os.read_file('.gitattributes')! == git_attributes_content
|
|
|
|
assert os.read_file('.editorconfig')! == editor_config_content
|
2022-01-20 14:01:30 +03:00
|
|
|
}
|
2022-09-16 04:56:19 +03:00
|
|
|
|
|
|
|
fn testsuite_end() {
|
|
|
|
os.rmdir_all(test_path) or {}
|
|
|
|
}
|