45 lines
880 B
YAML
45 lines
880 B
YAML
name: "Variable tests"
|
|||
|
|
cases:
|
||
|
|
- name: "Appending to a variable"
|
||
|
|
stdin: |
|
||
|
|
x=something
|
||
|
|
x+=here
|
||
|
|
echo "x: ${x}"
|
||
|
|
|
||
|
|
- name: "Appending an integer to an integer variable"
|
||
|
|
stdin: |
|
||
|
|
declare -i x=10
|
||
|
|
echo "x: ${x}"
|
||
|
|
x+=5
|
||
|
|
echo "x: ${x}"
|
||
|
|
x+=value
|
||
|
|
echo "x: ${x}"
|
||
|
|
|
||
|
|
y=value
|
||
|
|
declare -i y
|
||
|
|
echo "y: ${y}"
|
||
|
|
y+=5
|
||
|
|
echo "y: ${y}"
|
||
|
|
|
||
|
|
- name: "Append to an unset variable"
|
||
|
|
stdin: |
|
||
|
|
declare -a myvar
|
||
|
|
myvar+=abc
|
||
|
|
echo "myvar: ${myvar}"
|
||
|
|
|
||
|
|
declare -i myint
|
||
|
|
myint+=abc
|
||
|
|
echo "myint: ${myint}"
|
||
|
|
|
||
|
|
- name: "Parameter length of unset variable with nounset"
|
||
|
|
ignore_stderr: true
|
||
|
|
stdin: |
|
||
|
|
set -u
|
||
|
|
echo "${#unset_var}" 2>&1 || true
|
||
|
|
arr=()
|
||
|
|
echo "${#arr[0]}"
|
||
|
|
echo "${#arr[@]}"
|
||
|
|
arr2=(hello world)
|
||
|
|
echo "${#arr2[5]}"
|
||
|
|
echo "${#arr2[0]}"
|