@@ -12,6 +12,7 @@ import v.util.vtest
1212import runtime
1313import rand
1414import strings
15+ import v.build_constraint
1516
1617pub const max_header_len = get_max_header_len ()
1718
@@ -98,6 +99,8 @@ pub mut:
9899 hash string // used as part of the name of the temporary directory created for tests, to ease cleanup
99100
100101 exec_mode ActionMode = .compile // .compile_and_run only for `v test`
102+
103+ build_environment build_constraint.Environment // see the documentation in v.build_constraint
101104}
102105
103106pub fn (mut ts TestSession) add_failed_cmd (cmd string ) {
@@ -443,6 +446,9 @@ pub fn (mut ts TestSession) test() {
443446 printing_thread := spawn ts.print_messages ()
444447 pool_of_test_runners.set_shared_context (ts)
445448 ts.reporter.worker_threads_start (remaining_files, mut ts)
449+
450+ ts.build_environment = get_build_environment ()
451+
446452 // all the testing happens here:
447453 pool_of_test_runners.work_on_pointers (unsafe { remaining_files.pointers () })
448454
@@ -568,9 +574,23 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
568574 } else {
569575 os.quoted_path (generated_binary_fpath)
570576 }
577+ mut details := get_test_details (file)
578+ mut should_be_built := true
579+ if details.vbuild != '' {
580+ should_be_built = ts.build_environment.eval (details.vbuild) or {
581+ eprintln ('${file }:${details .vbuild_line }:17: error during parsing the `// v test build` expression `${details .vbuild }`: ${err }' )
582+ false
583+ }
584+ $if trace_should_be_built ? {
585+ eprintln ('${file } has specific build constraint: `${details .vbuild }` => should_be_built: `${should_be_built }`' )
586+ eprintln ('> env facts: ${ts .build_environment .facts }' )
587+ eprintln ('> env defines: ${ts .build_environment .defines }' )
588+ }
589+ }
590+
571591 ts.benchmark.step ()
572592 tls_bench.step ()
573- if ! ts.build_tools && abs_path in ts.skip_files {
593+ if ! ts.build_tools && ( ! should_be_built || abs_path in ts.skip_files) {
574594 ts.benchmark.skip ()
575595 tls_bench.skip ()
576596 if ! hide_skips {
@@ -599,7 +619,6 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
599619 ts.append_message_with_duration (.cmd_end, '' , cmd_duration, mtc)
600620
601621 if status != 0 {
602- details := get_test_details (file)
603622 os.setenv ('VTEST_RETRY_MAX' , '${details .retry }' , true )
604623 for retry := 1 ; retry < = details.retry; retry++ {
605624 if ! details.hide_retries {
@@ -686,7 +705,6 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
686705 println (r.output.split_into_lines ().filter (it .contains (' assert' )).join ('\n ' ))
687706 }
688707 if r.exit_code != 0 {
689- mut details := get_test_details (file)
690708 mut trimmed_output := r.output.trim_space ()
691709 if trimmed_output.len == 0 {
692710 // retry running at least 1 more time, to avoid CI false positives as much as possible
@@ -895,19 +913,25 @@ pub mut:
895913 retry int
896914 flaky bool // when flaky tests fail, the whole run is still considered successful, unless VTEST_FAIL_FLAKY is 1
897915 //
898- hide_retries bool // when true, all retry tries are silent; used by `vlib/v/tests/retry_test.v`
916+ hide_retries bool // when true, all retry tries are silent; used by `vlib/v/tests/retry_test.v`
917+ vbuild string // could be `!(windows && tinyc)`
918+ vbuild_line int // for more precise error reporting, if the `vbuild` expression is incorrect
899919}
900920
901921pub fn get_test_details (file string ) TestDetails {
902922 mut res := TestDetails{}
903923 lines := os.read_lines (file) or { [] }
904- for line in lines {
924+ for idx, line in lines {
905925 if line.starts_with ('// vtest retry:' ) {
906926 res.retry = line.all_after (':' ).trim_space ().int ()
907927 }
908928 if line.starts_with ('// vtest flaky:' ) {
909929 res.flaky = line.all_after (':' ).trim_space ().bool ()
910930 }
931+ if line.starts_with ('// vtest build:' ) {
932+ res.vbuild = line.all_after (':' ).trim_space ()
933+ res.vbuild_line = idx + 1
934+ }
911935 if line.starts_with ('// vtest hide_retries' ) {
912936 res.hide_retries = true
913937 }
@@ -949,3 +973,9 @@ fn get_max_header_len() int {
949973 }
950974 return cols
951975}
976+
977+ fn get_build_environment () & build_constraint.Environment {
978+ facts := os.getenv ('VBUILD_FACTS' ).split_any (',' )
979+ defines := os.getenv ('VBUILD_DEFINES' ).split_any (',' )
980+ return build_constraint.new_environment (facts, defines)
981+ }
0 commit comments