2021-06-16 19:57:51 +03:00
|
|
|
import os
|
|
|
|
|
2022-11-03 10:24:52 +03:00
|
|
|
const test_path = os.join_path(os.vtmp_dir(), 'v', 'vcreate_test')
|
2021-06-16 19:57:51 +03:00
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
fn init_and_check() ! {
|
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-10-16 09:28:57 +03:00
|
|
|
assert os.read_file('vcreate_test.v')! == [
|
2021-06-16 19:57:51 +03:00
|
|
|
'module main\n',
|
|
|
|
'fn main() {',
|
|
|
|
" println('Hello World!')",
|
|
|
|
'}',
|
|
|
|
'',
|
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('v.mod')! == [
|
2021-06-16 19:57:51 +03:00
|
|
|
'Module {',
|
|
|
|
" name: 'vcreate_test'",
|
|
|
|
" 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',
|
|
|
|
'vcreate_test',
|
|
|
|
'*.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
|
|
|
'',
|
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',
|
|
|
|
'indent_size = 4',
|
|
|
|
'',
|
|
|
|
].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
|
|
|
|
indent_size = 4
|
|
|
|
'
|
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 {}
|
|
|
|
}
|