unstructured/test_unstructured_ingest/check-num-dirs-output.sh
Roman Isecke 76efcf4dd7
chore: add shfmt (#2246)
### Description
Given all the shell files that now exist in the repo, would be nice to
have linting/formatting around them (in addition to the existing
shellcheck which doesn't do anything to format the shell code). This PR
introduces `shfmt` to both check for changes and apply formatting when
the associated make targets are called.
2023-12-12 01:04:15 +00:00

28 lines
931 B
Bash
Executable File

#!/usr/bin/env bash
# Description: Validate that the number of directories in the output directory is as expected.
#
# Arguments:
# - $1: The expected number of directories in the output directory.
# - $2: Name of the output folder. This is used to determine the structured output path.
set +e
EXPECTED_NUM_DIRS=$1
OUTPUT_FOLDER_NAME=$2
SCRIPT_DIR=$(dirname "$(realpath "$0")")
OUTPUT_ROOT=${OUTPUT_ROOT:-$SCRIPT_DIR}
OUTPUT_DIR=$OUTPUT_ROOT/structured-output/$OUTPUT_FOLDER_NAME
NUMBER_OF_FOUND_DIRS="$(find "$OUTPUT_DIR" -type d -exec printf '.' \; | wc -c | xargs)"
# Note: single brackets and "-ne" operator were necessary for evaluation in CI
if [ "$NUMBER_OF_FOUND_DIRS" -ne "$EXPECTED_NUM_DIRS" ]; then
echo
echo "$EXPECTED_NUM_DIRS directories were expected to be found."
echo "$NUMBER_OF_FOUND_DIRS directories were found instead."
echo "Name of the directories found:"
find "$OUTPUT_DIR" -type d
exit 1
fi