From e6b40289f227428901e246149c25ffef18dd4491 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 23 Mar 2022 09:10:50 +0200 Subject: Make project configuration variables non-nullable by default A project configuration variable with the NULL default value is naturally assumed nullable, for example: config [string] config.libhello.fallback_name ?= [null] Otherwise, to make a project configuration nullable we use the `null` variable attribute, for example: config [string, null] config.libhello.fallback_name ?= "World" --- tests/directive/config.testscript | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'tests/directive') diff --git a/tests/directive/config.testscript b/tests/directive/config.testscript index 4049fa0..fba858f 100644 --- a/tests/directive/config.testscript +++ b/tests/directive/config.testscript @@ -14,7 +14,7 @@ test.arguments = EOI +cat <=build/root.build - config [bool] config.test.fancy ?= false + config [bool, null] config.test.fancy ?= false print ($defined(config.test.fancy) ? $config.test.fancy : undefined) EOI @@ -114,7 +114,6 @@ test.arguments = EOE } - : default-none : { @@ -125,7 +124,7 @@ test.arguments = EOI +cat <=build/root.build - config [bool] config.test.fancy + config [bool, null] config.test.fancy print ($defined(config.test.fancy) ? $config.test.fancy : undefined) EOI @@ -166,6 +165,37 @@ test.arguments = EOE } +: non-nullable +: +{ + .include ../common.testscript + + +cat <+build/bootstrap.build + using config + EOI + + +cat <=build/root.build + config [bool] config.test.fancy ?= false + print ($defined(config.test.fancy) ? $config.test.fancy : undefined) + EOI + + # This must be a single, serial test since we are sharing config.build. + # + : test + : + cat <=buildfile; + ./: + EOI + + $* noop >'false' ; + $* noop config.test.fancy=false >'false' ; + $* noop config.test.fancy=true >'true' ; + + $* noop config.test.fancy=[null] 2>>~/EOE/ != 0 + /.+root.build:1:1: error: null value in non-nullable variable config\.test\.fancy/ + EOE +} + : report : { -- cgit v1.1