Skip to content

Commit

Permalink
ignore ID's in spec comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
hbmartin committed Oct 4, 2024
1 parent fe8d636 commit eb8d477
Showing 1 changed file with 59 additions and 6 deletions.
65 changes: 59 additions & 6 deletions test_specs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,73 @@ process_files() {
done
}

# Function to compare files ignoring unstable IDs
compare_files() {
local file1="$1"
local file2="$2"

# Use sed to replace id="..." with a placeholder
sed_command='s/id="[^"]*"/id="PLACEHOLDER"/g'

# Compare the files after replacing IDs
diff <(sed "$sed_command" "$file1") <(sed "$sed_command" "$file2")
}

# Process files from source_dir to output_dir
echo "Processing files from $source_dir to $output_dir"
process_files "$source_dir" "$output_dir"

# Compare output_dir with specs_dir
echo "Comparing results in $output_dir with $specs_dir"
diff_output=$(diff -r "$output_dir" "$specs_dir")
diff_found=false

# Recursive function to compare directories
compare_dirs() {
local dir1="$1"
local dir2="$2"

for file in "$dir1"/*; do
local rel_path="${file#$dir1/}"
local file2="$dir2/$rel_path"

if [ -d "$file" ]; then
# If it's a directory, recurse
compare_dirs "$file" "$file2"
elif [ -f "$file" ]; then
# If it's a file, compare
if [ ! -f "$file2" ]; then
echo "File missing in specs directory: $rel_path"
diff_found=true
else
diff_output=$(compare_files "$file" "$file2")
if [ -n "$diff_output" ]; then
echo "Differences found in file: $rel_path"
echo "$diff_output"
diff_found=true
fi
fi
fi
done

# Check for extra files in specs_dir
for file in "$dir2"/*; do
local rel_path="${file#$dir2/}"
local file1="$dir1/$rel_path"

if [ ! -e "$file1" ]; then
echo "Extra file in specs directory: $rel_path"
diff_found=true
fi
done
}

# Start the comparison
compare_dirs "$output_dir" "$specs_dir"

if [ -z "$diff_output" ]; then
echo "No differences found. Test passed."
if [ "$diff_found" = false ]; then
echo "No differences found (ignoring unstable IDs). Test passed."
exit 0
else
echo "Differences found. Test failed."
echo "Differences:"
echo "$diff_output"
echo "Differences found (ignoring unstable IDs). Test failed."
exit 1
fi

0 comments on commit eb8d477

Please sign in to comment.