From a9663e16d5765a42175ce6131b8cae5ecc622b17 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 6 Apr 2016 07:46:43 +0200 Subject: Test and fix override logic --- tests/variable/override/build/bootstrap.build | 2 + tests/variable/override/buildfile | 58 ++++++ tests/variable/override/cache | 13 ++ tests/variable/override/p/build/bootstrap.build | 1 + tests/variable/override/p/buildfile | 49 +++++ tests/variable/override/simple | 3 + tests/variable/override/test.sh | 240 ++++++++++++++++++++++++ 7 files changed, 366 insertions(+) create mode 100644 tests/variable/override/build/bootstrap.build create mode 100644 tests/variable/override/buildfile create mode 100644 tests/variable/override/cache create mode 100644 tests/variable/override/p/build/bootstrap.build create mode 100644 tests/variable/override/p/buildfile create mode 100644 tests/variable/override/simple create mode 100755 tests/variable/override/test.sh (limited to 'tests') diff --git a/tests/variable/override/build/bootstrap.build b/tests/variable/override/build/bootstrap.build new file mode 100644 index 0000000..1c2e239 --- /dev/null +++ b/tests/variable/override/build/bootstrap.build @@ -0,0 +1,2 @@ +project = override +amalgamation = # Disabled. diff --git a/tests/variable/override/buildfile b/tests/variable/override/buildfile new file mode 100644 index 0000000..18c9831 --- /dev/null +++ b/tests/variable/override/buildfile @@ -0,0 +1,58 @@ +if ("$t" != "") +{ + [$t] v = [null] +} + +print "/ :" $(/: v) + +if ($a == as) +{ + v = x +} +elif ($a == ap) +{ + v += s +} +elif ($a == pr) +{ + v =+ p +} + +print ". :" $v + +d/: +{ + if ($d_a == as) + { + v = x + } + elif ($d_a == ap) + { + v += s + } + elif ($d_a == pr) + { + v =+ p + } + + print "d :" $v + + + if ($d_t_a == as) + { + file{t}: v = x + } + elif ($d_t_a == ap) + { + file{t}: v += s + } + elif ($d_t_a == pr) + { + file{t}: v =+ p + } + + print "d/t :" $(file{t}: v) +} + +include p/ +./: diff --git a/tests/variable/override/cache b/tests/variable/override/cache new file mode 100644 index 0000000..8378688 --- /dev/null +++ b/tests/variable/override/cache @@ -0,0 +1,13 @@ +x = [string] 0 +print $x + +x = [uint64] 1 +print $x + +y = 0 +print $y + +[uint64] y = [null] +print $y + +./: diff --git a/tests/variable/override/p/build/bootstrap.build b/tests/variable/override/p/build/bootstrap.build new file mode 100644 index 0000000..723e2a3 --- /dev/null +++ b/tests/variable/override/p/build/bootstrap.build @@ -0,0 +1 @@ +project = override-p diff --git a/tests/variable/override/p/buildfile b/tests/variable/override/p/buildfile new file mode 100644 index 0000000..527b9ae --- /dev/null +++ b/tests/variable/override/p/buildfile @@ -0,0 +1,49 @@ +if ($p_a == as) +{ + v = x +} +elif ($p_a == ap) +{ + v += s +} +elif ($p_a == pr) +{ + v =+ p +} + +print "p :" $v + +d/: +{ + if ($p_d_a == as) + { + v = x + } + elif ($p_d_a == ap) + { + v += s + } + elif ($p_d_a == pr) + { + v =+ p + } + + print "p/d :" $v + + if ($p_d_t_a == as) + { + file{t}: v = x + } + elif ($p_d_t_a == ap) + { + file{t}: v += s + } + elif ($p_d_t_a == pr) + { + file{t}: v =+ p + } + + print "p/d/t :" $(file{t}: v) +} + +./: diff --git a/tests/variable/override/simple b/tests/variable/override/simple new file mode 100644 index 0000000..899daa2 --- /dev/null +++ b/tests/variable/override/simple @@ -0,0 +1,3 @@ +print $foo + +./: diff --git a/tests/variable/override/test.sh b/tests/variable/override/test.sh new file mode 100755 index 0000000..a195766 --- /dev/null +++ b/tests/variable/override/test.sh @@ -0,0 +1,240 @@ +#! /usr/bin/env bash + +verbose=n + +function error () { echo "$*" 1>&2; exit 1; } + +function fail () +{ + if [ "$verbose" = "y" ]; then + b $* + else + b -q $* 2>/dev/null + fi + + if [ $? -eq 0 ]; then + error "succeeded: b $*" + fi + + return 0 +} + +function test () +{ + # There is no way to get the exit code in process substitution + # so ruin the output. + # + diff -u - <(b -q $* || echo "") + + if [ $? -ne 0 ]; then + error "failed: b $*" + fi +} + +fail foo=bar[] # error: unexpected [ in variable assignment 'foo=bar[]' +fail foo=[string]bar # error: typed override of variable foo +fail "!foo=bar" "!foo=BAR" # error: multiple global overrides of variable foo +fail "foo=bar" "foo=BAR" # error: multiple project overrides of variable foo +fail "%foo=bar" "%foo=BAR" # error: multiple project overrides of variable foo + +test --buildfile simple foo=bar ./ ./ <<< "bar" # Multiple bootstraps of the same project. + +# Visibility. +# +test !v=X <