From 892f602159695b0f9e3fc3ca3bd1c4165a936700 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 16 Dec 2023 00:39:11 +0000 Subject: [PATCH] Revert "Remove bash snapshot tests" This reverts commit 9a5ec76d7c50e49acb44997ba04e6359f3da79ff. --- run | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/run b/run index b0704a1..62a85c1 100755 --- a/run +++ b/run @@ -37,6 +37,7 @@ function build { function ci:test { nix develop --command composer install + nix develop --command ./run test:snapshots nix develop --command phpunit --testdox } @@ -71,5 +72,42 @@ function test:create-snapshot { git status "${output_path}" } +# Generate a file and ensure it matches the expected version. +function test:snapshots { + rm -rf .ignored/snapshots + mkdir -p .ignored/snapshots + + local configs=( + # TODO: add more configurations for different types and configurations. + drupal + drupal-commerce-kickstart + drupal-localgov + fractal + ) + + for config in "${configs[@]}"; do + config_file="tests/snapshots/configs/${config}.yaml" + input_path="tests/snapshots/output/${config}" + output_path=".ignored/snapshots/output/${config}" + + cat "${config_file}" + + ./bin/build-configs app:generate --config-file "${config_file}" --output-dir "${output_path}" + + find "${input_path}" -type f -print0 | while IFS= read -r -d '' original_file; do + generated_file="${output_path}/${original_file#"${input_path}"/}" + + if cmp -s "${original_file}" "${generated_file}"; then + echo "Files match: ${original_file}" + else + # TODO: show the diff for all failed files. This will stop after the first failure. + echo "Files do not match: ${original_file}" + diff "${original_file}" "${generated_file}" + exit 1 + fi + done + done +} + TIMEFORMAT=$'\nTask completed in %3lR' time "${@:-help}"