v2 / vlib / v / builder / cc_tcc_retry_test.v
60 lines · 51 sloc · 2.41 KB · e93194b0eb97822be79c03a8de0fda3cc5e49bc9
Raw
1module builder
2
3import os
4
5fn test_is_tcc_compilation_failure_detects_tcc_kind() {
6 assert is_tcc_compilation_failure('cc', .tcc, '')
7}
8
9fn test_is_tcc_compilation_failure_detects_tcc_compiler_name() {
10 assert is_tcc_compilation_failure('tcc', .unknown, '')
11 assert is_tcc_compilation_failure('/opt/v/thirdparty/tcc/tcc.exe', .unknown, '')
12 assert is_tcc_compilation_failure('/usr/local/bin/tcc-0.9.27', .unknown, '')
13 assert !is_tcc_compilation_failure('/usr/bin/clang', .unknown, '')
14}
15
16fn test_is_tcc_compilation_failure_detects_tcc_output() {
17 assert is_tcc_compilation_failure('cc', .unknown, 'tcc: error: bad architecture')
18 assert is_tcc_compilation_failure('cc', .unknown, 'line 1\nline 2\ntcc: error: lib not found')
19 assert !is_tcc_compilation_failure('cc', .unknown, 'clang: error: unsupported option')
20}
21
22fn test_is_tcc_compilation_failure_detects_tcc_alias_compiler() {
23 if os.user_os() == 'windows' {
24 return
25 }
26 test_root := os.join_path(os.vtmp_dir(), 'v_builder_cc_tcc_retry_test_${os.getpid()}')
27 cc_path := os.join_path(test_root, 'cc')
28 old_path := os.getenv('PATH')
29 os.mkdir_all(test_root) or { panic(err) }
30 os.write_file(cc_path, '#!/bin/sh\necho "Tiny C Compiler"\n') or { panic(err) }
31 os.chmod(cc_path, 0o700) or { panic(err) }
32 os.setenv('PATH', '${test_root}${os.path_delimiter}${old_path}', true)
33 defer {
34 os.setenv('PATH', old_path, true)
35 os.rmdir_all(test_root) or {}
36 }
37 assert is_tcc_compilation_failure('cc', .unknown, '')
38}
39
40fn fake_windows_short_path(path string) string {
41 return path.replace(r'C:\Users\Léo', r'C:\Users\LEO~1')
42}
43
44fn test_rewrite_windows_path_arg_rewrites_quoted_object_paths() {
45 arg := r'"C:\Users\Léo\.vmodules\.cache\bc\artifact.o"'
46 expected := r'"C:\Users\LEO~1\.vmodules\.cache\bc\artifact.o"'
47 assert rewrite_windows_path_arg(arg, fake_windows_short_path) == expected
48}
49
50fn test_rewrite_windows_path_arg_rewrites_prefixed_paths() {
51 assert rewrite_windows_path_arg(r'-I"C:\Users\Léo\include"', fake_windows_short_path) == r'-I"C:\Users\LEO~1\include"'
52 assert rewrite_windows_path_arg(r'-L"C:\Users\Léo\lib"', fake_windows_short_path) == r'-L"C:\Users\LEO~1\lib"'
53 assert rewrite_windows_path_arg(r'-o "C:\Users\Léo\bin\tool.exe"', fake_windows_short_path) == r'-o "C:\Users\LEO~1\bin\tool.exe"'
54}
55
56fn test_rewrite_windows_path_arg_leaves_non_paths_alone() {
57 for arg in ['-bt25', '-std=c99', '-D_DEFAULT_SOURCE'] {
58 assert rewrite_windows_path_arg(arg, fake_windows_short_path) == arg
59 }
60}
61