From 0bbf2b584834915711e202fdcad0574ba7ed7b8a Mon Sep 17 00:00:00 2001 From: "Dave Musicant (home machine)" Date: Sun, 4 Dec 2022 11:57:38 -0600 Subject: [PATCH] new approach for trying to dup space bug --- tests/spaces.bats | 50 +++++++++--------------------- tests/startup-shutdown-spaces.bash | 41 ++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 35 deletions(-) create mode 100755 tests/startup-shutdown-spaces.bash diff --git a/tests/spaces.bats b/tests/spaces.bats index 8c7cd15..510b663 100644 --- a/tests/spaces.bats +++ b/tests/spaces.bats @@ -2,30 +2,12 @@ # This inserts customs setup and teardown because of spaces in the file name -function spaces_in_target_dir { #@test - # Time to wait for gitwatch to respond - # shellcheck disable=SC2034 - WAITTIME=4 - # Set up directory structure and initialize remote - testdir=$(mktemp -d "/tmp/tmpspace.XXXXXXX") - # shellcheck disable=SC2164 - cd "$testdir" - mkdir remote - # shellcheck disable=SC2164 - cd remote - git init -q --bare - # shellcheck disable=SC2103 - cd .. - # shellcheck disable=SC2164 - mkdir local - # shellcheck disable=SC2164 - cd local - git clone -q ../remote +load startup-shutdown-spaces +function spaces_in_target_dir { #@test # Start up gitwatch with logging, see if works "${BATS_TEST_DIRNAME}"/../gitwatch.sh -l 10 "$testdir/local/remote" 3>&- & GITWATCH_PID=$! - echo "$GITWATCH_PID" # Keeps kill message from printing to screen disown @@ -33,23 +15,21 @@ function spaces_in_target_dir { #@test # Create a file, verify that it hasn't been added yet, then commit cd remote - echo '# Teardown started' >&3 - # Remove testing directories - # shellcheck disable=SC2164 - cd /tmp + # According to inotify documentation, a race condition results if you write + # to directory too soon after it has been created; hence, a short wait. + sleep 1 + echo "line1" >> file1.txt - # Kill background process - # kill -9 %1 - # fg + # Wait a bit for inotify to figure out the file has changed, and do its add, + # and commit + sleep "$WAITTIME" - # Also make sure to kill fswatch if on Mac - killall fswatch || true - # Make sure gitwatch script gets killed if script stopped background - # Must kill the entire tree of processes generated - pkill -15 -f gitwatch.sh - pkill -15 -f gitwatch.sh - # pkill -15 -P "$GITWATCH_PID" + # Make a new change + echo "line2" >> file1.txt + sleep "$WAITTIME" - echo '# Teardown complete' >&3 + # Check commit log that the diff is in there + run git log -1 --oneline + [[ $output == *"file1.txt"* ]] } diff --git a/tests/startup-shutdown-spaces.bash b/tests/startup-shutdown-spaces.bash new file mode 100755 index 0000000..82c21fe --- /dev/null +++ b/tests/startup-shutdown-spaces.bash @@ -0,0 +1,41 @@ +# This inserts customs setup and teardown because of spaces in the file name + +setup() { + # Time to wait for gitwatch to respond + # shellcheck disable=SC2034 + WAITTIME=4 + # Set up directory structure and initialize remote + testdir=$(mktemp -d "/tmp/tmp space.XXXXXXX") + # shellcheck disable=SC2164 + cd "$testdir" + mkdir remote + # shellcheck disable=SC2164 + cd remote + git init -q --bare + # shellcheck disable=SC2103 + cd .. + # shellcheck disable=SC2164 + mkdir local + # shellcheck disable=SC2164 + cd local + git clone -q ../remote +} + +teardown() { + echo '# Teardown started' >&3 + # Remove testing directories + # shellcheck disable=SC2164 + cd /tmp + + # Kill background process + kill -9 %1 + fg + + # Also make sure to kill fswatch if on Mac + killall fswatch + # Make sure gitwatch script gets killed if script stopped background + # Must kill the entire tree of processes generated + pkill -15 -P "$GITWATCH_PID" + + echo '# Teardown complete' >&3 +}