2017-02-12 20:28:48 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-02-12 20:55:06 +00:00
|
|
|
set -e
|
|
|
|
|
2017-02-12 20:28:48 +00:00
|
|
|
# acceptance test
|
|
|
|
|
2020-12-01 03:14:16 +00:00
|
|
|
|
|
|
|
|
2020-12-01 03:23:27 +00:00
|
|
|
echo "test eval-sequence"
|
2020-12-01 03:14:16 +00:00
|
|
|
random=$((1 + $RANDOM % 10))
|
|
|
|
./yq e -n ".a = $random" > test.yml
|
|
|
|
X=$(./yq e '.a' test.yml)
|
|
|
|
|
|
|
|
if [[ $X != $random ]]; then
|
|
|
|
echo "Failed create: expected $random but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-12-01 03:23:27 +00:00
|
|
|
echo "--success"
|
|
|
|
|
|
|
|
echo "test update-in-place"
|
2020-12-01 03:14:16 +00:00
|
|
|
|
|
|
|
update=$(($random + 1))
|
|
|
|
./yq e -i ".a = $update" test.yml
|
|
|
|
|
|
|
|
X=$(./yq e '.a' test.yml)
|
|
|
|
if [[ $X != $update ]]; then
|
|
|
|
echo "Failed to update inplace test: expected $update but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-12-01 03:23:27 +00:00
|
|
|
echo "--success"
|
|
|
|
|
|
|
|
echo "test eval-all"
|
|
|
|
./yq ea -n ".a = $random" > test-eval-all.yml
|
|
|
|
Y=$(./yq ea '.a' test-eval-all.yml)
|
|
|
|
|
|
|
|
if [[ $Y != $random ]]; then
|
|
|
|
echo "Failed create with eval all: expected $random but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "--success"
|
2020-12-01 03:14:16 +00:00
|
|
|
|
2020-12-01 03:23:27 +00:00
|
|
|
echo "test no exit status"
|
|
|
|
./yq e '.z' test.yml
|
|
|
|
echo "--success"
|
2020-12-01 03:14:16 +00:00
|
|
|
|
2020-12-01 03:23:27 +00:00
|
|
|
echo "test exit status"
|
2020-12-01 03:14:16 +00:00
|
|
|
set +e
|
|
|
|
|
2020-12-01 03:23:27 +00:00
|
|
|
./yq e -e '.z' test.yml
|
2020-12-01 03:14:16 +00:00
|
|
|
|
|
|
|
if [[ $? != 1 ]]; then
|
|
|
|
echo "Expected error code 1 but was $?"
|
2017-02-12 20:28:48 +00:00
|
|
|
exit 1
|
2017-09-20 23:40:33 +00:00
|
|
|
fi
|
2020-12-01 03:14:16 +00:00
|
|
|
|
2021-07-16 11:08:20 +00:00
|
|
|
echo "Test: leading seperator logic"
|
2021-07-14 10:48:16 +00:00
|
|
|
expected=$(cat examples/leading-seperator.yaml)
|
|
|
|
|
|
|
|
X=$(cat examples/leading-seperator.yaml | ./yq e '.' -)
|
|
|
|
if [[ $X != $expected ]]; then
|
|
|
|
echo "Pipe into e"
|
|
|
|
echo "Expected $expected but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
X=$(./yq e '.' examples/leading-seperator.yaml)
|
|
|
|
expected=$(cat examples/leading-seperator.yaml)
|
|
|
|
if [[ $X != $expected ]]; then
|
|
|
|
echo "read given file e"
|
|
|
|
echo "Expected $expected but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
X=$(cat examples/leading-seperator.yaml | ./yq ea '.' -)
|
|
|
|
if [[ $X != $expected ]]; then
|
|
|
|
echo "Pipe into e"
|
|
|
|
echo "Expected $expected but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
X=$(./yq ea '.' examples/leading-seperator.yaml)
|
|
|
|
expected=$(cat examples/leading-seperator.yaml)
|
|
|
|
if [[ $X != $expected ]]; then
|
|
|
|
echo "read given file e"
|
|
|
|
echo "Expected $expected but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# multidoc
|
|
|
|
read -r -d '' expected << EOM
|
|
|
|
---
|
|
|
|
a: test
|
|
|
|
---
|
|
|
|
version: 3
|
|
|
|
application: MyApp
|
|
|
|
EOM
|
|
|
|
|
|
|
|
X=$(./yq e '.' examples/leading-seperator.yaml examples/order.yaml)
|
|
|
|
|
|
|
|
if [[ $X != $expected ]]; then
|
|
|
|
echo "Multidoc with leading seperator"
|
|
|
|
echo "Expected $expected but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
X=$(./yq ea '.' examples/leading-seperator.yaml examples/order.yaml)
|
|
|
|
|
|
|
|
if [[ $X != $expected ]]; then
|
|
|
|
echo "Multidoc with leading seperator"
|
|
|
|
echo "Expected $expected but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-07-16 11:08:20 +00:00
|
|
|
echo "Test: handle empty files"
|
2021-07-16 10:56:22 +00:00
|
|
|
./yq e '.' examples/empty.yaml
|
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
echo "Expected no error when processing empty file but got one"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat examples/empty.yaml | ./yq e '.' -
|
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
echo "Expected no error when processing empty stdin but got one"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-07-16 11:08:20 +00:00
|
|
|
# run expression against empty file
|
2021-07-18 03:17:35 +00:00
|
|
|
rm -f temp.yaml
|
2021-07-16 11:08:20 +00:00
|
|
|
touch temp.yaml
|
|
|
|
expected="apple: tree"
|
|
|
|
|
|
|
|
./yq e '.apple = "tree"' temp.yaml -i
|
|
|
|
X=$(cat temp.yaml)
|
2021-07-18 03:17:35 +00:00
|
|
|
rm -f temp.yaml
|
2021-07-16 11:08:20 +00:00
|
|
|
if [[ $X != $expected ]]; then
|
|
|
|
echo "Write empty doc"
|
|
|
|
echo "Expected $expected but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
touch temp.yaml
|
|
|
|
|
|
|
|
./yq ea '.apple = "tree"' temp.yaml -i
|
|
|
|
X=$(cat temp.yaml)
|
2021-07-18 03:17:35 +00:00
|
|
|
rm -f temp.yaml
|
2021-07-16 11:08:20 +00:00
|
|
|
if [[ $X != $expected ]]; then
|
|
|
|
echo "Write all empty doc"
|
|
|
|
echo "Expected $expected but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-07-16 10:56:22 +00:00
|
|
|
|
2021-07-16 12:08:22 +00:00
|
|
|
echo "Test: handle empty files with just comments"
|
2021-07-18 03:17:35 +00:00
|
|
|
rm -f temp.yaml
|
2021-07-16 12:08:22 +00:00
|
|
|
echo "# comment" > temp.yaml
|
|
|
|
read -r -d '' expected << EOM
|
|
|
|
# comment
|
|
|
|
apple: tree
|
|
|
|
EOM
|
|
|
|
|
|
|
|
./yq e '.apple = "tree"' temp.yaml -i
|
|
|
|
X=$(cat temp.yaml)
|
2021-07-18 03:17:35 +00:00
|
|
|
rm -f temp.yaml
|
2021-07-16 12:08:22 +00:00
|
|
|
if [[ $X != $expected ]]; then
|
|
|
|
echo "Write empty doc"
|
|
|
|
echo "Expected $expected but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "# comment" > temp.yaml
|
|
|
|
|
|
|
|
./yq ea '.apple = "tree"' temp.yaml -i
|
|
|
|
X=$(cat temp.yaml)
|
2021-07-18 03:17:35 +00:00
|
|
|
rm -f temp.yaml
|
2021-07-16 12:08:22 +00:00
|
|
|
if [[ $X != $expected ]]; then
|
|
|
|
echo "Write all empty doc"
|
|
|
|
echo "Expected $expected but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-07-18 03:17:35 +00:00
|
|
|
echo "Test: eval front matter process"
|
|
|
|
|
|
|
|
cat >temp.yaml <<EOL
|
|
|
|
---
|
|
|
|
a: apple
|
|
|
|
b: cat
|
|
|
|
---
|
|
|
|
not yaml
|
|
|
|
c: at
|
|
|
|
EOL
|
|
|
|
|
|
|
|
read -r -d '' expected << EOM
|
|
|
|
---
|
|
|
|
a: apple
|
|
|
|
b: dog
|
|
|
|
---
|
|
|
|
not yaml
|
|
|
|
c: at
|
|
|
|
EOM
|
|
|
|
|
|
|
|
./yq e --front-matter="process" '.b = "dog"' temp.yaml -i
|
|
|
|
X=$(cat temp.yaml)
|
|
|
|
rm -f temp.yaml
|
|
|
|
if [[ $X != $expected ]]; then
|
|
|
|
echo "eval fail"
|
|
|
|
echo "Expected $expected but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Test: eval front matter extract"
|
|
|
|
|
|
|
|
cat >temp.yaml <<EOL
|
|
|
|
a: apple
|
|
|
|
b: cat
|
|
|
|
---
|
|
|
|
not yaml
|
|
|
|
c: at
|
|
|
|
EOL
|
|
|
|
|
|
|
|
read -r -d '' expected << EOM
|
|
|
|
a: apple
|
|
|
|
b: dog
|
|
|
|
EOM
|
|
|
|
|
|
|
|
./yq e --front-matter="extract" '.b = "dog"' temp.yaml -i
|
|
|
|
X=$(cat temp.yaml)
|
|
|
|
rm -f temp.yaml
|
|
|
|
if [[ $X != $expected ]]; then
|
|
|
|
echo "eval fail"
|
|
|
|
echo "Expected $expected but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Test: eval-all front matter process"
|
|
|
|
|
|
|
|
cat >temp.yaml <<EOL
|
|
|
|
---
|
|
|
|
a: apple
|
|
|
|
b: cat
|
|
|
|
---
|
|
|
|
not yaml
|
|
|
|
c: at
|
|
|
|
EOL
|
|
|
|
|
|
|
|
read -r -d '' expected << EOM
|
|
|
|
---
|
|
|
|
a: apple
|
|
|
|
b: dog
|
|
|
|
---
|
|
|
|
not yaml
|
|
|
|
c: at
|
|
|
|
EOM
|
|
|
|
|
|
|
|
./yq ea --front-matter="process" '.b = "dog"' temp.yaml -i
|
|
|
|
X=$(cat temp.yaml)
|
|
|
|
rm -f temp.yaml
|
|
|
|
if [[ $X != $expected ]]; then
|
|
|
|
echo "eval fail"
|
|
|
|
echo "Expected $expected but was $X"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-12-01 03:23:27 +00:00
|
|
|
echo "--success"
|
2020-12-01 03:14:16 +00:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
rm test.yml
|
2020-12-01 03:23:27 +00:00
|
|
|
rm test-eval-all.yml
|
2017-12-17 22:11:08 +00:00
|
|
|
echo "acceptance tests passed"
|