From d970a8fce22c62bd99468f679c19b9cd2c5481b2 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 12 Mar 2025 15:35:06 +0200 Subject: [PATCH] v.build_constraint: support `// vtest build: false` and `// vtest build: true` too; add tests --- vlib/v/build_constraint/constraint_test.v | 15 +++++++++++++++ vlib/v/build_constraint/public.v | 1 + 2 files changed, 16 insertions(+) diff --git a/vlib/v/build_constraint/constraint_test.v b/vlib/v/build_constraint/constraint_test.v index cc5f330de1..c7e5b066d8 100644 --- a/vlib/v/build_constraint/constraint_test.v +++ b/vlib/v/build_constraint/constraint_test.v @@ -15,6 +15,21 @@ fn test_eval_define() { assert !benv.is_define('xyz') } +fn test_eval_true() { + assert benv.eval('true')! +} + +fn test_eval_false() { + assert !benv.eval('false')! +} + +fn test_eval_comment() { + assert benv.eval('true // some comment')! + assert benv.eval(' true// another comment ...')! + assert !benv.eval('false // some comment')! + assert !benv.eval(' false// another comment ...')! +} + fn test_eval_platforms_and_compilers() { assert benv.eval('tinyc')! assert benv.eval(' tinyc')! diff --git a/vlib/v/build_constraint/public.v b/vlib/v/build_constraint/public.v index bdf1db94c6..bc9eed6aa4 100644 --- a/vlib/v/build_constraint/public.v +++ b/vlib/v/build_constraint/public.v @@ -13,6 +13,7 @@ pub mut: // `defines` is a list of the user defines, for example: ['abc', 'gcboehm_opt', 'gg_record', 'show_fps'] pub fn new_environment(facts []string, defines []string) &Environment { mut b := &Environment{} + b.facts['true'] = true for f in facts { b.facts[f] = true }