1# CHECK: -- Testing:{{.*}} 2# CHECK-NEXT: PASS: shtest-if-else :: test.txt (1 of 1) 3# CHECK: Command Output (stdout): 4# CHECK-NEXT: -- 5 6# RUN: %if feature %{ echo "test-1" %} 7# CHECK: # {{RUN}}: at line [[#@LINE-1]] 8# CHECK-NEXT: echo "test-1" 9 10# If %else is not present it is treated like %else %{%}. Empty commands 11# are ignored. 12# 13# RUN: %if nofeature %{ echo "fail" %} 14# CHECK: # {{RUN}}: at line [[#@LINE-1]] has no command after substitutions 15# CHECK-NOT: fail 16 17# RUN: %if nofeature %{ echo "fail" %} %else %{ echo "test-2" %} 18# CHECK: # {{RUN}}: at line [[#@LINE-1]] 19# CHECK-NEXT: echo "test-2" 20 21# Spaces inside curly braces are not ignored 22# 23# RUN: echo test-%if feature %{ 3 %} %else %{ fail %}-test 24# RUN: echo test-%if feature %{ 4 4 %} %else %{ fail %}-test 25# RUN: echo test-%if nofeature %{ fail %} %else %{ 5 5 %}-test 26# CHECK: # {{RUN}}: at line [[#@LINE-3]] 27# CHECK-NEXT: echo test- 3 -test 28# CHECK: # {{RUN}}: at line [[#@LINE-4]] 29# CHECK-NEXT: echo test- 4 4 -test 30# CHECK: # {{RUN}}: at line [[#@LINE-5]] 31# CHECK-NEXT: echo test- 5 5 -test 32 33# Escape line breaks for multi-line expressions 34# 35# RUN: %if feature \ 36# RUN: %{ echo \ 37# RUN: "test-5" \ 38# RUN: %} 39# CHECK: # {{RUN}}: at line [[#@LINE-4]] 40# CHECK-NEXT: echo "test-5" 41 42# RUN: %if nofeature \ 43# RUN: %{ echo "fail" %} \ 44# RUN: %else \ 45# RUN: %{ echo "test-6" %} 46# CHECK: # {{RUN}}: at line [[#@LINE-4]] 47# CHECK-NEXT: echo "test-6" 48 49# RUN: echo "test%if feature %{%} %else %{%}-7" 50# CHECK: # {{RUN}}: at line [[#@LINE-1]] 51# CHECK-NEXT: echo "test-7" 52 53# Escape %if. Without %if..%else context '%{' and '%}' are treated 54# literally. 55# 56# RUN: echo %%if feature %{ echo "test-8" %} 57# CHECK: # {{RUN}}: at line [[#@LINE-1]] 58# CHECK-NEXT: echo %if feature %{ echo "test-8" %} 59 60# Nested expressions are supported: 61# 62# RUN: echo %if feature %{ %if feature %{ %if nofeature %{"fail"%} %else %{"test-9"%} %} %} 63# CHECK: # {{RUN}}: at line [[#@LINE-1]] 64# CHECK-NEXT: echo "test-9" 65 66# Binary expression evaluation and regex match can be used as 67# conditions. 68# 69# RUN: echo %if feature && !nofeature %{ "test-10" %} 70# RUN: echo %if feature && nofeature %{ "fail" %} %else %{ "test-11" %} 71# RUN: echo %if {{fea.+}} %{ "test-12" %} %else %{ "fail" %} 72# CHECK: # {{RUN}}: at line [[#@LINE-3]] 73# CHECK-NEXT: echo "test-10" 74# CHECK: # {{RUN}}: at line [[#@LINE-4]] 75# CHECK-NEXT: echo "test-11" 76# CHECK: # {{RUN}}: at line [[#@LINE-5]] 77# CHECK-NEXT: echo "test-12" 78 79# Spaces between %if and %else are ignored. If there is no %else - 80# space after %if %{...%} is not ignored. 81# 82# RUN: echo XX %if feature %{YY%} ZZ 83# RUN: echo AA %if feature %{BB%} %else %{CC%} DD 84# RUN: echo AA %if nofeature %{BB%} %else %{CC%} DD 85# CHECK: # {{RUN}}: at line [[#@LINE-3]] 86# CHECK-NEXT: echo XX YY ZZ 87# CHECK: # {{RUN}}: at line [[#@LINE-4]] 88# CHECK-NEXT: echo AA BB DD 89# CHECK: # {{RUN}}: at line [[#@LINE-5]] 90# CHECK-NEXT: echo AA CC DD 91 92# '{' and '}' can be used without escaping 93# 94# RUN: %if feature %{echo {}%} 95# CHECK: # {{RUN}}: at line [[#@LINE-1]] 96# CHECK-NEXT: echo {} 97 98# Spaces are not required 99# 100# RUN: echo %if feature%{"ok"%}%else%{"fail"%} 101# CHECK: # {{RUN}}: at line [[#@LINE-1]] 102# CHECK-NEXT: echo "ok" 103 104# Substitutions with braces are handled correctly 105# 106# RUN: echo %{sub} %if feature%{test-%{sub}%}%else%{"fail"%} 107# CHECK: # {{RUN}}: at line [[#@LINE-1]] 108# CHECK-NEXT: echo ok test-ok 109