From db18e75a09e07a903c6cea650649720a4092a0e6 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Tue, 11 Aug 2020 16:44:55 +0430 Subject: [PATCH] Shell: Add tests for 'if' --- Shell/Tests/if.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Shell/Tests/if.sh diff --git a/Shell/Tests/if.sh b/Shell/Tests/if.sh new file mode 100644 index 0000000000..342579da26 --- /dev/null +++ b/Shell/Tests/if.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +if test 1 -eq 1 { + # Are comments ok? + # Basic 'if' structure, empty block. + if true { + } else { + exit 2 + } + if false { + exit 2 + } else { + } + + # Basic 'if' structure, without 'else' + if false { + echo "Fail: 'if false' runs the branch" + exit 2 + } + + # Extended 'cond' form. + if false { + echo "Fail: 'if false' with 'else if' runs first branch" + exit 2 + } else if true { + } else { + echo "Fail: 'if false' with 'else if' runs last branch" + exit 2 + } + + # FIXME: Some form of 'not' would be nice + # &&/|| in condition + if true || false { + } else { + echo "Fail: 'if true || false' runs false branch" + exit 2 + } + + if true && false { + echo "Fail: 'if true && false' runs true branch" + exit 2 + } +} else { + echo "Fail: 'if test 1 -eq 1' runs false branch" + exit 1 +}