diff --git a/vlib/v/pref/options_test.v b/vlib/v/pref/options_test.v index e83a510bb2..b552e61f4c 100644 --- a/vlib/v/pref/options_test.v +++ b/vlib/v/pref/options_test.v @@ -4,49 +4,53 @@ 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') - // + os.chdir(os.real_path(@VMODROOT)) or {} 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') + println('> test whether -cflags is passed to the backend C compiler') + fail := custom_compile('failing.exe', 'NONSENSE_OPTION') + assert fail.compilation.exit_code != 0 + println('> NONSENSE_OPTION failed the C build, OK') // - 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') + dbg := custom_compile('debug_hw.exe', debug_arg) + assert dbg.compilation.exit_code == 0 + assert dbg.file_size > 0 + // + opt := custom_compile('optimised_hw.exe', optimised_arg) + assert opt.compilation.exit_code == 0 + assert opt.file_size > 0 // $if !tinyc { // tcc does almost no optimisations, so the differences are very insignificant - assert optimised_file_size != debug_file_size // optimised_file_size should be smaller in general, but not on the Ubuntu CI for some reason :-| - assert optimised_delta >= debug_delta + assert opt.file_size != dbg.file_size // optimised_file_size should be smaller in general, but not on the Ubuntu CI for some reason :-| + // assert optimised_delta >= debug_delta // this is not reliable on the CIs :-| } - os.rm(optexe) or {} - os.rm(dbgexe) or {} + os.rm(opt.exe) or {} + os.rm(dbg.exe) or {} +} + +fn custom_compile(fname string, cflags_options string) Results { + mut res := Results{} + res.exe = os.join_path(os.temp_dir(), fname) + res.sw = time.new_stopwatch() + res.compilation = os.execute('"$vexe" -cflags "$cflags_options" -o "$res.exe" examples/hello_world.v') + res.delta = res.sw.elapsed().microseconds() + res.file_size = os.file_size(res.exe) + println('> $fname build took: $res.delta ms with "$cflags_options", file size: $res.file_size') + return res +} + +struct Results { +mut: + exe string + sw time.StopWatch + compilation os.Result + delta i64 + file_size u64 }