Skip to content

Instantly share code, notes, and snippets.

@oprypin
Last active April 19, 2020 11:07
Show Gist options
  • Save oprypin/ab4656fbc6f9c64023ac971a23562242 to your computer and use it in GitHub Desktop.
Save oprypin/ab4656fbc6f9c64023ac971a23562242 to your computer and use it in GitHub Desktop.
Unused code deletion based on the output not being affected
#!/bin/bash
set -x -e
check() {
mkdir -p /tmp/a /tmp/b
cp generate.cr /tmp/a/
sed -i -e "${1}d" generate.cr
cp generate.cr /tmp/b/
(cd /tmp/b && crystal build --warnings=none generate.cr) || return 4
(cd /tmp/a && crystal build --warnings=none generate.cr) || return 5
for sfml in ~/downloads/SFML-*/include; do
a="/tmp/a/$sfml/gen"
b="/tmp/b/$sfml/gen"
rm -r "$a" "$b"
mkdir -p "$a" "$b"
(cd "$b" && timeout 2 /tmp/b/generate "$sfml" &>out.txt) || return 2
(cd "$a" && timeout 2 /tmp/a/generate "$sfml" &>out.txt) || return 3
diff -r "$a" "$b" || return 1
done
}
for l in $(seq $(wc -l <generate.cr) -1 1); do
if check "$l"; then
git add generate.cr
else
git checkout -- generate.cr
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment