From dc652d4d091098367f78c4dfbf6aef101cc06bf8 Mon Sep 17 00:00:00 2001 From: Nitsan Avni Date: Fri, 5 Jan 2024 09:11:27 +0100 Subject: [PATCH] . t bash/texttest_fixture.sh temp file -> variable --- bash/texttest_fixture.sh | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/bash/texttest_fixture.sh b/bash/texttest_fixture.sh index 690c9833..7018f127 100755 --- a/bash/texttest_fixture.sh +++ b/bash/texttest_fixture.sh @@ -2,11 +2,8 @@ GILDED_ROSE_SCRIPT="./gilded_rose.sh" -create_initial_items() { - local temp_file=$(mktemp) - - cat <"$temp_file" -+5 Dexterity Vest|10|20 +# Define initial items as a multi-line string +initial_items="+5 Dexterity Vest|10|20 Aged Brie|2|0 Elixir of the Mongoose|5|7 Sulfuras, Hand of Ragnaros|0|80 @@ -14,25 +11,20 @@ Sulfuras, Hand of Ragnaros|-1|80 Backstage passes to a TAFKAL80ETC concert|15|20 Backstage passes to a TAFKAL80ETC concert|10|49 Backstage passes to a TAFKAL80ETC concert|5|49 -Conjured Mana Cake|3|6 -EOF - - echo "$temp_file" -} +Conjured Mana Cake|3|6" simulate_days() { local days=$1 - local items_file=$2 + local items="$2" for ((day = 0; day <= days; day++)); do echo "-------- day $day --------" echo "name, sellIn, quality" - cat "$items_file" | sed 's/|/, /g' + echo "$items" | sed 's/|/, /g' - local temp_output=$(mktemp) - cat "$items_file" | bash "$GILDED_ROSE_SCRIPT" >"$temp_output" - mv "$temp_output" "$items_file" + # Update the items for the next day + items=$(echo "$items" | bash "$GILDED_ROSE_SCRIPT") echo "" done @@ -40,10 +32,6 @@ simulate_days() { echo OMGHAI! -ITEMS_FILE=$(create_initial_items) - DAYS_TO_SIMULATE=${1:-2} -simulate_days $DAYS_TO_SIMULATE $ITEMS_FILE - -rm "$ITEMS_FILE" +simulate_days $DAYS_TO_SIMULATE "$initial_items"