Skip to content

Commit

Permalink
Fix scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
korenyoni committed Nov 2, 2023
1 parent 7b96937 commit f7da9cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
11 changes: 6 additions & 5 deletions testing/equivalence/compare-results.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#!/bin/bash

path=$(which realpath)
if [[ "$OSTYPE" == "darwin"* ]];
then
if ! command -v grealpath &> /dev/null;
then
print_style "ERROR: This script requires grealpath when run on Mac. Please install it with 'brew install coreutils'\n" "danger"
exit 1
else
alias realpath=grealpath
path=$(which grealpath)
fi
fi

source $(grealpath $(dirname $0))/lib.sh
source $($path $(dirname $0))/lib.sh

for i in $(find $(grealpath $(dirname $0))/results/terraform -mindepth 1 -maxdepth 1 -type d); do
for i in $(find $($path $(dirname $0))/results/terraform -mindepth 1 -maxdepth 1 -type d); do
test_case_name=$(basename ${i})
print_style "Test case "
print_style "${test_case_name}" "info"
Expand All @@ -25,8 +26,8 @@ for i in $(find $(grealpath $(dirname $0))/results/terraform -mindepth 1 -maxdep
print_style "results/opentofu/$(basename ${f})" "info"
print_style ": "

terraform_file=$(grealpath $(dirname $0))/results/terraform/$(basename ${i})/$(basename ${f})
opentofu_file=$(grealpath $(dirname $0))/results/opentofu/$(basename ${i})/$(basename ${f})
terraform_file=$($path $(dirname $0))/results/terraform/$(basename ${i})/$(basename ${f})
opentofu_file=$($path $(dirname $0))/results/opentofu/$(basename ${i})/$(basename ${f})

# We normalize the JSON output to make them comparable regardless of key order
diff \
Expand Down
21 changes: 11 additions & 10 deletions testing/equivalence/update-test-cases.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#!/bin/bash

source $(realpath $(dirname $0))/lib.sh

path=$(which realpath)
if [[ "$OSTYPE" == "darwin"* ]];
then
if ! command -v grealpath &> /dev/null;
then
print_style "ERROR: This script requires grealpath when run on Mac. Please install it with 'brew install coreutils'\n" "danger"
exit 1
else
alias realpath=grealpath
path=$(which grealpath)
fi
fi

source $(realpath $(dirname $0))/lib.sh

test_case_dirname="test_cases"
test_case_prefix="test_"

Expand All @@ -33,25 +34,25 @@ if [[ ! -d ${test_case_dirname} ]]; then
mkdir -p ${test_case_dirname}
fi

for i in $(find $(dirname $(grealpath $0))/../../examples -mindepth 1 -maxdepth 1 -type d -not -path "**/.modules"); do
for i in $(find $(dirname $($path $0))/../../examples -mindepth 1 -maxdepth 1 -type d -not -path "**/.modules"); do
if [[ " ${skip_examples[@]} " =~ " $(basename ${i}) " ]]; then
print_style "Skipping example "
print_style "$(grealpath --relative-to=$(dirname $0) ${i})\n" "warning"
print_style "$($path --relative-to=$(dirname $0) ${i})\n" "warning"
continue
fi

print_style "Found example directory: "
print_style "$(grealpath --relative-to=$(dirname $0) ${i})\n"
expected_test_dir="$(dirname $(grealpath $0))/${test_case_dirname}/${test_case_prefix}$(basename ${i})"
print_style "$($path --relative-to=$(dirname $0) ${i})\n"
expected_test_dir="$(dirname $($path $0))/${test_case_dirname}/${test_case_prefix}$(basename ${i})"

if [[ ! -d ${expected_test_dir} ]]; then
mkdir -p ${expected_test_dir}
print_style " * created missing directory "
print_style "$(grealpath --relative-to=$(dirname $0) ${expected_test_dir})\n" "warning"
print_style "$($path --relative-to=$(dirname $0) ${expected_test_dir})\n" "warning"
fi

print_style " * updating "
print_style "$(grealpath --relative-to=$(dirname $0) ${expected_test_dir})/main.tf\n" "info"
print_style "$($path --relative-to=$(dirname $0) ${expected_test_dir})/main.tf\n" "info"
cat << EOF > ${expected_test_dir}/main.tf
# DO NOT EDIT
# This file is automatically generated by $(basename $0)
Expand All @@ -61,7 +62,7 @@ module test {
EOF

print_style " * updating "
print_style "$(grealpath --relative-to=$(dirname $0) ${expected_test_dir})/spec.json\n" "info"
print_style "$($path --relative-to=$(dirname $0) ${expected_test_dir})/spec.json\n" "info"
cat << EOF > ${expected_test_dir}/spec.json
{
"ignore_fields": {
Expand Down

0 comments on commit f7da9cd

Please sign in to comment.