aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-06-10 10:32:15 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-06-10 10:32:15 +0200
commit28e9fd496fd39d180a2d786378c4ff396b9f69c8 (patch)
tree39c3b9c30b3255054e7a4a80b57990cb1375a3af
parent1ea33ab70f88fcfebf388a9a438e3c1e56fbdf0f (diff)
Add ad hoc recipe if-else, switch tests (and fix bug)
-rw-r--r--libbuild2/parser.cxx14
-rw-r--r--tests/dependency/recipe/testscript149
2 files changed, 159 insertions, 4 deletions
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx
index 36e75a3..21b5794 100644
--- a/libbuild2/parser.cxx
+++ b/libbuild2/parser.cxx
@@ -1356,6 +1356,13 @@ namespace build2
m.name = "perform";
}
}
+ else
+ {
+ // Default is perform(update).
+ //
+ bs.push_back (metaopspec ("perform"));
+ bs.back ().push_back (opspec ("update"));
+ }
expire_mode ();
next_after_newline (t, tt, "recipe action");
@@ -1395,11 +1402,10 @@ namespace build2
// Fall through.
}
-
- // Default is perform(update).
- //
- if (bs.empty ())
+ else
{
+ // Default is perform(update).
+ //
bs.push_back (metaopspec ("perform"));
bs.back ().push_back (opspec ("update"));
}
diff --git a/tests/dependency/recipe/testscript b/tests/dependency/recipe/testscript
index ee598b7..5f9bdf1 100644
--- a/tests/dependency/recipe/testscript
+++ b/tests/dependency/recipe/testscript
@@ -390,6 +390,155 @@ EOI
<stdin>:5:3: error: duplicate recipe for perform(update)
EOE
+: if-else
+:
+$* <<EOI 2>>/~%EOE%
+f = false
+alias{x}: alias{z}
+%
+if $f
+{{
+ false
+}}
+else
+{{
+ echo
+}}
+dump alias{x}
+EOI
+<stdin>:12:1: dump:
+% .+/alias\{x\}: .+/:alias\{z\}%
+ % [diag=echo] perform(update)
+ {{
+ echo
+ }}
+EOE
+
+: if-else-replay
+:
+$* <<EOI 2>>/~%EOE%
+f = false
+alias{x y}: alias{z}
+%
+if $f
+{{
+ false
+}}
+else
+{{
+ echo
+}}
+dump alias{y}
+EOI
+<stdin>:12:1: dump:
+% .+/alias\{y\}: .+/:alias\{z\}%
+ % [diag=echo] perform(update)
+ {{
+ echo
+ }}
+EOE
+
+: if-no-else
+:
+$* <<EOI 2>>/~%EOE%
+f = false
+alias{x}: alias{z}
+%
+if $f
+{{
+ false
+}}
+dump alias{x}
+EOI
+<stdin>:8:1: dump:
+% .+/alias\{x\}: .+/:alias\{z\}%
+EOE
+
+: switch
+:
+$* <<EOI 2>>/~%EOE%
+f = 2
+alias{x}: alias{z}
+%
+switch $f
+{
+ case 1
+ {{
+ false
+ }}
+ case 2
+ {{
+ echo
+ }}
+ default
+ {{
+ false
+ }}
+}
+dump alias{x}
+EOI
+<stdin>:19:1: dump:
+% .+/alias\{x\}: .+/:alias\{z\}%
+ % [diag=echo] perform(update)
+ {{
+ echo
+ }}
+EOE
+
+: switch-replay
+:
+$* <<EOI 2>>/~%EOE%
+f = 2
+alias{x y}: alias{z}
+%
+switch $f
+{
+ case 1
+ {{
+ false
+ }}
+ case 2
+ {{
+ echo
+ }}
+ default
+ {{
+ false
+ }}
+}
+dump alias{y}
+EOI
+<stdin>:19:1: dump:
+% .+/alias\{y\}: .+/:alias\{z\}%
+ % [diag=echo] perform(update)
+ {{
+ echo
+ }}
+EOE
+
+: switch-no-default
+:
+$* <<EOI 2>>/~%EOE%
+f = 2
+alias{x}: alias{z}
+%
+switch $f
+{
+ case 0
+ {{
+ false
+ }}
+ case 1
+ {{
+ echo
+ }}
+}
+dump alias{x}
+EOI
+<stdin>:15:1: dump:
+% .+/alias\{x\}: .+/:alias\{z\}%
+EOE
+
: diag
:
{