#!/bin/sh # shellcheck shell=dash # Load code to be tested . ../lib oneTimeSetUp() { if [ -n "${VERBOSE:-}" ]; then printf "[INFO] Current shell is: %s\n" "$( "$TEST_TMPDIR/input.txt" substitute \ "$TEST_TMPDIR/input.txt" \ "$TEST_TMPDIR/output.txt" \ "hello" "goodbye" assertEquals "goodbye world" "$(cat "$TEST_TMPDIR/output.txt")" } testSubstitute_Multi() { echo "hello hello hello" > "$TEST_TMPDIR/input.txt" substitute \ "$TEST_TMPDIR/input.txt" \ "$TEST_TMPDIR/output.txt" \ "hello" "hi" assertEquals "hi hi hi" "$(cat "$TEST_TMPDIR/output.txt")" } testSubstitute_Multiline() { printf "hello\nworld\nhello\nworld\n" > "$TEST_TMPDIR/input.txt" substitute \ "$TEST_TMPDIR/input.txt" \ "$TEST_TMPDIR/output.txt" \ "hello\nworld" "$(printf "greetings\nall")" assertEquals \ "$(printf "greetings\nall\ngreetings\nall")" \ "$(cat "$TEST_TMPDIR/output.txt")" } testSubstituteInPlace() { echo "hello hello hello" > "$TEST_TMPDIR/sub.txt" substituteInPlace \ "$TEST_TMPDIR/sub.txt" \ "hello" "hi" assertEquals "hi hi hi" "$(cat "$TEST_TMPDIR/sub.txt")" } testQuote() { local input expected { input="$(cat)"; } <