Skip to content

Commit

Permalink
Factor out common code in shell tests. (#2552)
Browse files Browse the repository at this point in the history
  • Loading branch information
maryla-uc authored Jan 6, 2025
1 parent 1346d9c commit 1ebddd3
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 274 deletions.
43 changes: 43 additions & 0 deletions tests/cmd_test_common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------
#
# Common code for command line tests. Should be source'd at the beginning of
# the test: source $(dirname "$0")/cmd_test_common.sh

# Very verbose but useful for debugging.
set -ex

if [[ "$#" -ge 1 ]]; then
# eval so that the passed in directory can contain variables.
BINARY_DIR="$(eval echo "$1")"
else
# Assume "tests" is the current directory.
BINARY_DIR="$(pwd)/.."
fi
if [[ "$#" -ge 2 ]]; then
TESTDATA_DIR="$(eval echo "$2")"
else
TESTDATA_DIR="$(pwd)/data"
fi
if [[ "$#" -ge 3 ]]; then
TMP_DIR="$(eval echo "$3")"
else
TMP_DIR="$(mktemp -d)"
fi

AVIFENC="${BINARY_DIR}/avifenc"
AVIFDEC="${BINARY_DIR}/avifdec"
ARE_IMAGES_EQUAL="${BINARY_DIR}/tests/are_images_equal"
25 changes: 1 addition & 24 deletions tests/test_cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,7 @@
#
# tests for command lines

# Very verbose but useful for debugging.
set -ex

if [[ "$#" -ge 1 ]]; then
# eval so that the passed in directory can contain variables.
BINARY_DIR="$(eval echo "$1")"
else
# Assume "tests" is the current directory.
BINARY_DIR="$(pwd)/.."
fi
if [[ "$#" -ge 2 ]]; then
TESTDATA_DIR="$(eval echo "$2")"
else
TESTDATA_DIR="$(pwd)/data"
fi
if [[ "$#" -ge 3 ]]; then
TMP_DIR="$(eval echo "$3")"
else
TMP_DIR="$(mktemp -d)"
fi

AVIFENC="${BINARY_DIR}/avifenc"
AVIFDEC="${BINARY_DIR}/avifdec"
ARE_IMAGES_EQUAL="${BINARY_DIR}/tests/are_images_equal"
source $(dirname "$0")/cmd_test_common.sh

# Basic calls.
"${AVIFENC}" --version
Expand Down
22 changes: 1 addition & 21 deletions tests/test_cmd_animation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,7 @@
# limitations under the License.
# ------------------------------------------------------------------------------

set -ex

if [[ "$#" -ge 1 ]]; then
BINARY_DIR="$(eval echo "$1")"
else
BINARY_DIR="$(pwd)/.."
fi
if [[ "$#" -ge 2 ]]; then
TESTDATA_DIR="$(eval echo "$2")"
else
TESTDATA_DIR="$(pwd)/data"
fi
if [[ "$#" -ge 3 ]]; then
TMP_DIR="$(eval echo "$3")"
else
TMP_DIR="$(mktemp -d)"
fi

AVIFENC="${BINARY_DIR}/avifenc"
AVIFDEC="${BINARY_DIR}/avifdec"
ARE_IMAGES_EQUAL="${BINARY_DIR}/tests/are_images_equal"
source $(dirname "$0")/cmd_test_common.sh

# Input file paths.
INPUT_Y4M_0="${TESTDATA_DIR}/kodim03_yuv420_8bpc.y4m"
Expand Down
23 changes: 1 addition & 22 deletions tests/test_cmd_avifgainmaputil.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,9 @@
#
# tests for command lines (avifgainmaputil tool)

# Very verbose but useful for debugging.
set -ex

if [[ "$#" -ge 1 ]]; then
# eval so that the passed in directory can contain variables.
BINARY_DIR="$(eval echo "$1")"
else
# Assume "tests" is the current directory.
BINARY_DIR="$(pwd)/.."
fi
if [[ "$#" -ge 2 ]]; then
TESTDATA_DIR="$(eval echo "$2")"
else
TESTDATA_DIR="$(pwd)/data"
fi
if [[ "$#" -ge 3 ]]; then
TMP_DIR="$(eval echo "$3")"
else
TMP_DIR="$(mktemp -d)"
fi
source $(dirname "$0")/cmd_test_common.sh

AVIFGAINMAPUTIL="${BINARY_DIR}/avifgainmaputil"
AVIFENC="${BINARY_DIR}/avifenc"
ARE_IMAGES_EQUAL="${BINARY_DIR}/tests/are_images_equal"

# Input file paths.
INPUT_AVIF_GAINMAP_SDR="${TESTDATA_DIR}/seine_sdr_gainmap_srgb.avif"
Expand Down
25 changes: 1 addition & 24 deletions tests/test_cmd_avm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,7 @@
#
# tests for command lines

# Very verbose but useful for debugging.
set -ex

if [[ "$#" -ge 1 ]]; then
# eval so that the passed in directory can contain variables.
BINARY_DIR="$(eval echo "$1")"
else
# Assume "tests" is the current directory.
BINARY_DIR="$(pwd)/.."
fi
if [[ "$#" -ge 2 ]]; then
TESTDATA_DIR="$(eval echo "$2")"
else
TESTDATA_DIR="$(pwd)/data"
fi
if [[ "$#" -ge 3 ]]; then
TMP_DIR="$(eval echo "$3")"
else
TMP_DIR="$(mktemp -d)"
fi

AVIFENC="${BINARY_DIR}/avifenc"
AVIFDEC="${BINARY_DIR}/avifdec"
ARE_IMAGES_EQUAL="${BINARY_DIR}/tests/are_images_equal"
source $(dirname "$0")/cmd_test_common.sh

# Basic calls.
"${AVIFENC}" --version
Expand Down
25 changes: 1 addition & 24 deletions tests/test_cmd_avm_lossless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,7 @@
#
# tests for command lines (lossless)

# Very verbose but useful for debugging.
set -ex

if [[ "$#" -ge 1 ]]; then
# eval so that the passed in directory can contain variables.
BINARY_DIR="$(eval echo "$1")"
else
# Assume "tests" is the current directory.
BINARY_DIR="$(pwd)/.."
fi
if [[ "$#" -ge 2 ]]; then
TESTDATA_DIR="$(eval echo "$2")"
else
TESTDATA_DIR="$(pwd)/data"
fi
if [[ "$#" -ge 3 ]]; then
TMP_DIR="$(eval echo "$3")"
else
TMP_DIR="$(mktemp -d)"
fi

AVIFENC="${BINARY_DIR}/avifenc"
AVIFDEC="${BINARY_DIR}/avifdec"
ARE_IMAGES_EQUAL="${BINARY_DIR}/tests/are_images_equal"
source $(dirname "$0")/cmd_test_common.sh

# Input file paths.
INPUT_PNG="${TESTDATA_DIR}/ArcTriomphe-cHRM-orig.png"
Expand Down
23 changes: 1 addition & 22 deletions tests/test_cmd_gainmap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,7 @@
#
# tests for command lines (gain maps)

# Very verbose but useful for debugging.
set -ex

if [[ "$#" -ge 1 ]]; then
# eval so that the passed in directory can contain variables.
BINARY_DIR="$(eval echo "$1")"
else
# Assume "tests" is the current directory.
BINARY_DIR="$(pwd)/.."
fi
if [[ "$#" -ge 2 ]]; then
TESTDATA_DIR="$(eval echo "$2")"
else
TESTDATA_DIR="$(pwd)/data"
fi
if [[ "$#" -ge 3 ]]; then
TMP_DIR="$(eval echo "$3")"
else
TMP_DIR="$(mktemp -d)"
fi

AVIFENC="${BINARY_DIR}/avifenc"
source $(dirname "$0")/cmd_test_common.sh

# Input file paths.
INPUT_JPEG_GAINMAP="${TESTDATA_DIR}/paris_exif_xmp_gainmap_bigendian.jpg"
Expand Down
25 changes: 1 addition & 24 deletions tests/test_cmd_grid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,7 @@
#
# tests for command lines (grid)

# Very verbose but useful for debugging.
set -ex

if [[ "$#" -ge 1 ]]; then
# eval so that the passed in directory can contain variables.
BINARY_DIR="$(eval echo "$1")"
else
# Assume "tests" is the current directory.
BINARY_DIR="$(pwd)/.."
fi
if [[ "$#" -ge 2 ]]; then
TESTDATA_DIR="$(eval echo "$2")"
else
TESTDATA_DIR="$(pwd)/data"
fi
if [[ "$#" -ge 3 ]]; then
TMP_DIR="$(eval echo "$3")"
else
TMP_DIR="$(mktemp -d)"
fi

AVIFENC="${BINARY_DIR}/avifenc"
AVIFDEC="${BINARY_DIR}/avifdec"
ARE_IMAGES_EQUAL="${BINARY_DIR}/tests/are_images_equal"
source $(dirname "$0")/cmd_test_common.sh

# Input file paths.
INPUT_PNG="${TESTDATA_DIR}/paris_icc_exif_xmp.png" # 403 x 302 px
Expand Down
25 changes: 1 addition & 24 deletions tests/test_cmd_icc_profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,7 @@
#
# tests for command lines (icc profile)

# Very verbose but useful for debugging.
set -ex

if [[ "$#" -ge 1 ]]; then
# eval so that the passed in directory can contain variables.
BINARY_DIR="$(eval echo "$1")"
else
# Assume "tests" is the current directory.
BINARY_DIR="$(pwd)/.."
fi
if [[ "$#" -ge 2 ]]; then
TESTDATA_DIR="$(eval echo "$2")"
else
TESTDATA_DIR="$(pwd)/data"
fi
if [[ "$#" -ge 3 ]]; then
TMP_DIR="$(eval echo "$3")"
else
TMP_DIR="$(mktemp -d)"
fi

AVIFENC="${BINARY_DIR}/avifenc"
AVIFDEC="${BINARY_DIR}/avifdec"
ARE_IMAGES_EQUAL="${BINARY_DIR}/tests/are_images_equal"
source $(dirname "$0")/cmd_test_common.sh

# Input file paths.
INPUT_COLOR_PNG="${TESTDATA_DIR}/ArcTriomphe-cHRM-red-green-swap.png"
Expand Down
25 changes: 1 addition & 24 deletions tests/test_cmd_lossless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,7 @@
#
# tests for command lines (lossless)

# Very verbose but useful for debugging.
set -ex

if [[ "$#" -ge 1 ]]; then
# eval so that the passed in directory can contain variables.
BINARY_DIR="$(eval echo "$1")"
else
# Assume "tests" is the current directory.
BINARY_DIR="$(pwd)/.."
fi
if [[ "$#" -ge 2 ]]; then
TESTDATA_DIR="$(eval echo "$2")"
else
TESTDATA_DIR="$(pwd)/data"
fi
if [[ "$#" -ge 3 ]]; then
TMP_DIR="$(eval echo "$3")"
else
TMP_DIR="$(mktemp -d)"
fi

AVIFENC="${BINARY_DIR}/avifenc"
AVIFDEC="${BINARY_DIR}/avifdec"
ARE_IMAGES_EQUAL="${BINARY_DIR}/tests/are_images_equal"
source $(dirname "$0")/cmd_test_common.sh

# Input file paths.
INPUT_PNG="${TESTDATA_DIR}/paris_icc_exif_xmp.png"
Expand Down
24 changes: 1 addition & 23 deletions tests/test_cmd_metadata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,7 @@
#
# tests for command lines (metadata)

# Very verbose but useful for debugging.
set -ex

if [[ "$#" -ge 1 ]]; then
# eval so that the passed in directory can contain variables.
BINARY_DIR="$(eval echo "$1")"
else
# Assume "tests" is the current directory.
BINARY_DIR="$(pwd)/.."
fi
if [[ "$#" -ge 2 ]]; then
TESTDATA_DIR="$(eval echo "$2")"
else
TESTDATA_DIR="$(pwd)/data"
fi
if [[ "$#" -ge 3 ]]; then
TMP_DIR="$(eval echo "$3")"
else
TMP_DIR="$(mktemp -d)"
fi

AVIFENC="${BINARY_DIR}/avifenc"
AVIFDEC="${BINARY_DIR}/avifdec"
source $(dirname "$0")/cmd_test_common.sh

# Input file paths.
INPUT_PNG="${TESTDATA_DIR}/paris_icc_exif_xmp.png"
Expand Down
24 changes: 1 addition & 23 deletions tests/test_cmd_progressive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,7 @@
# limitations under the License.
# ------------------------------------------------------------------------------

# Very verbose but useful for debugging.
set -ex

if [[ "$#" -ge 1 ]]; then
# eval so that the passed in directory can contain variables.
BINARY_DIR="$(eval echo "$1")"
else
# Assume "tests" is the current directory.
BINARY_DIR="$(pwd)/.."
fi
if [[ "$#" -ge 2 ]]; then
TESTDATA_DIR="$(eval echo "$2")"
else
TESTDATA_DIR="$(pwd)/data"
fi
if [[ "$#" -ge 3 ]]; then
TMP_DIR="$(eval echo "$3")"
else
TMP_DIR="$(mktemp -d)"
fi

AVIFENC="${BINARY_DIR}/avifenc"
AVIFDEC="${BINARY_DIR}/avifdec"
source $(dirname "$0")/cmd_test_common.sh

# Basic calls.
"${AVIFENC}" --version
Expand Down
Loading

0 comments on commit 1ebddd3

Please sign in to comment.