From 72ceb1f2cdc86ca706524097bd8c4d3c2a8a26f6 Mon Sep 17 00:00:00 2001 From: Kattouf Date: Wed, 17 Jul 2024 13:15:09 +0700 Subject: [PATCH] relocate snapshots dir --- Tests/assert.sh | 15 +++++++++++++-- {snapshots => Tests/snapshots}/default.snapshot | 0 .../snapshots}/default_with_original_log.snapshot | 0 ...efault_with_original_log_original_log.snapshot | 0 {snapshots => Tests/snapshots}/log_all.snapshot | 0 .../snapshots}/log_matches.snapshot | 0 6 files changed, 13 insertions(+), 2 deletions(-) rename {snapshots => Tests/snapshots}/default.snapshot (100%) rename {snapshots => Tests/snapshots}/default_with_original_log.snapshot (100%) rename {snapshots => Tests/snapshots}/default_with_original_log_original_log.snapshot (100%) rename {snapshots => Tests/snapshots}/log_all.snapshot (100%) rename {snapshots => Tests/snapshots}/log_matches.snapshot (100%) diff --git a/Tests/assert.sh b/Tests/assert.sh index 4e25e4d..a8e3f81 100644 --- a/Tests/assert.sh +++ b/Tests/assert.sh @@ -1,3 +1,14 @@ +#!/usr/bin/env bash +# +# Determine if the script is sourced or executed +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then + # Script is being sourced + SNAPSHOTS_DIR="$(cd "$(dirname "${BASH_SOURCE[1]}")" && pwd)" +else + # Script is being executed + SNAPSHOTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +fi + # takes a name for snapshot file and string to compare to reference. # If the snapshot file does not exist, it will be created. # If the snapshot file does exist, the string will be compared to the snapshot. @@ -6,8 +17,8 @@ assert_snapshot() { local snapshot_name="$1" local snapshot_value="$2" - local snapshot_file="snapshots/$snapshot_name.snapshot" - mkdir -p snapshots + local snapshot_file="$SNAPSHOTS_DIR/snapshots/$snapshot_name.snapshot" + mkdir -p "$SNAPSHOTS_DIR" if [ "$SNAPSHOT_RECORD" = "true" ]; then echo "Recording snapshot $snapshot_name" >&2 diff --git a/snapshots/default.snapshot b/Tests/snapshots/default.snapshot similarity index 100% rename from snapshots/default.snapshot rename to Tests/snapshots/default.snapshot diff --git a/snapshots/default_with_original_log.snapshot b/Tests/snapshots/default_with_original_log.snapshot similarity index 100% rename from snapshots/default_with_original_log.snapshot rename to Tests/snapshots/default_with_original_log.snapshot diff --git a/snapshots/default_with_original_log_original_log.snapshot b/Tests/snapshots/default_with_original_log_original_log.snapshot similarity index 100% rename from snapshots/default_with_original_log_original_log.snapshot rename to Tests/snapshots/default_with_original_log_original_log.snapshot diff --git a/snapshots/log_all.snapshot b/Tests/snapshots/log_all.snapshot similarity index 100% rename from snapshots/log_all.snapshot rename to Tests/snapshots/log_all.snapshot diff --git a/snapshots/log_matches.snapshot b/Tests/snapshots/log_matches.snapshot similarity index 100% rename from snapshots/log_matches.snapshot rename to Tests/snapshots/log_matches.snapshot