mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.pref: add a simple options_test.v to check for -cflags regressions
This commit is contained in:
parent
8501217a4e
commit
6b2cc9c5cf
@ -287,16 +287,16 @@ pub fn (mut v Builder) cc_msvc() {
|
||||
a << ['-w', '/we4013', '/volatile:ms', '/Fo"$out_name_obj"']
|
||||
if v.pref.is_prod {
|
||||
a << '/O2'
|
||||
a << '/MD'
|
||||
a << '/DNDEBUG'
|
||||
} else {
|
||||
a << '/MDd'
|
||||
a << '/D_DEBUG'
|
||||
}
|
||||
if v.pref.is_debug {
|
||||
a << '/MDd'
|
||||
a << '/D_DEBUG'
|
||||
// /Zi generates a .pdb
|
||||
// /Fd sets the pdb file name (so its not just vc140 all the time)
|
||||
a << ['/Zi', '/Fd"$out_name_pdb"']
|
||||
} else {
|
||||
a << '/MD'
|
||||
a << '/DNDEBUG'
|
||||
}
|
||||
if v.pref.is_shared {
|
||||
if !v.pref.out_name.ends_with('.dll') {
|
||||
|
@ -33,7 +33,7 @@ fn test_out_files() ? {
|
||||
print(term.colorize(term.magenta, 'v run $relpath') + ' == ' +
|
||||
term.colorize(term.magenta, out_relpath) + ' ')
|
||||
pexe := os.join_path(output_path, '${basename}.exe')
|
||||
compilation := os.execute('$vexe -o $pexe $path')
|
||||
compilation := os.execute('"$vexe" -o "$pexe" "$path"')
|
||||
ensure_compilation_succeeded(compilation)
|
||||
res := os.execute(pexe)
|
||||
if res.exit_code < 0 {
|
||||
|
52
vlib/v/pref/options_test.v
Normal file
52
vlib/v/pref/options_test.v
Normal file
@ -0,0 +1,52 @@
|
||||
// vtest retry: 3
|
||||
import os
|
||||
import time
|
||||
|
||||
const vexe = @VEXE
|
||||
|
||||
const vroot = os.real_path(@VMODROOT)
|
||||
|
||||
fn testsuite_begin() {
|
||||
os.chdir(vroot) or {}
|
||||
}
|
||||
|
||||
fn test_cflags() ? {
|
||||
println('> test whether -cflags is passed to the backend C compiler')
|
||||
compilation := os.execute('"$vexe" -cflags NONSENSE_OPTION examples/hello_world.v')
|
||||
assert compilation.exit_code != 0
|
||||
println('> NONSENSE_OPTION failed the C build, OK')
|
||||
//
|
||||
mut debug_arg := '-g3 -O0'
|
||||
mut optimised_arg := '-O1'
|
||||
$if msvc {
|
||||
debug_arg = '/MDd /D_DEBUG'
|
||||
optimised_arg = '/O1'
|
||||
}
|
||||
tmpdir := os.temp_dir()
|
||||
//
|
||||
dbgexe := os.join_path(os.temp_dir(), 'debug_hw.exe')
|
||||
debug_sw := time.new_stopwatch()
|
||||
debug_compilation := os.execute('"$vexe" -cflags "$debug_arg" -o "$dbgexe" examples/hello_world.v')
|
||||
debug_delta := debug_sw.elapsed().microseconds()
|
||||
assert debug_compilation.exit_code == 0
|
||||
debug_file_size := os.file_size(dbgexe)
|
||||
assert debug_file_size > 0
|
||||
println('> debug build took: $debug_delta ms with "$debug_arg", file size: $debug_file_size')
|
||||
//
|
||||
optexe := os.join_path(os.temp_dir(), 'optimised_hw.exe')
|
||||
optimised_sw := time.new_stopwatch()
|
||||
optimised_compilation := os.execute('"$vexe" -cflags "$optimised_arg" -o "$optexe" examples/hello_world.v')
|
||||
optimised_delta := optimised_sw.elapsed().microseconds()
|
||||
assert optimised_compilation.exit_code == 0
|
||||
optimised_file_size := os.file_size(optexe)
|
||||
assert optimised_file_size > 0
|
||||
println('> optimised build took: $optimised_delta ms with "$optimised_arg", file size: $optimised_file_size')
|
||||
//
|
||||
$if !tinyc {
|
||||
// tcc does almost no optimisations, so the differences are very insignificant
|
||||
assert optimised_file_size <= debug_file_size
|
||||
assert optimised_delta >= debug_delta
|
||||
}
|
||||
os.rm(optexe) or {}
|
||||
os.rm(dbgexe) or {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user