git-lfs/t/t-malformed-pointers.sh
Chris Darroch fef4c0ff98 t: pipe data to base64 to be compatible with macOS
The base64(1) binary provided with macOS does not accept a bare input
file name, unlike any of the GNU coreutils implementations of base64(1)
or either the older Fourmilab or newer bintrans(1) BSD implementations.
Instead, it appears to be a version unique to OS X which requires an -i
option before a file name to be used for input.  See, for reference:

  https://www.unix.com/man-page/osx/1/base64/
  https://man7.org/linux/man-pages/man1/base64.1.html
  https://www.fourmilab.ch/webtools/base64/
  https://man.freebsd.org/cgi/man.cgi?query=base64&manpath=FreeBSD+15.0-CURRENT

With the Xcode developer tools for macOS installed, along with Go, Git,
etc., our test suite mostly succeeds, but several tests fail because
they expect to call base64(1) and pass the bare /dev/urandom file name.

We can resolve this inconvenience for developers by adjusting those
tests to use the technique we already use in the t/t-migrate-*.sh
test suites where we redirect /dev/urandom into base64 as its
standard input.  This allows the test suites to function on both
macOS as well as Linux systems which use one of the other base64(1)
implementations.
2024-01-10 20:29:43 -08:00

93 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
begin_test "malformed pointers"
(
set -e
reponame="malformed-pointers"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
git add .gitattributes
git commit -m "initial commit"
base64 < /dev/urandom | head -c 1023 > malformed_small.dat
base64 < /dev/urandom | head -c 1024 > malformed_exact.dat
base64 < /dev/urandom | head -c 1025 > malformed_large.dat
base64 < /dev/urandom | head -c 1048576 > malformed_xxl.dat
git \
-c "filter.lfs.process=" \
-c "filter.lfs.clean=cat" \
-c "filter.lfs.required=false" \
add *.dat
git commit -m "add malformed pointer"
git push origin main
pushd .. >/dev/null
clone_repo "$reponame" "$reponame-assert"
grep "malformed_small.dat" clone.log
grep "malformed_exact.dat" clone.log
grep "malformed_large.dat" clone.log
grep "malformed_xxl.dat" clone.log
expected_small="$(cat ../$reponame/malformed_small.dat)"
expected_exact="$(cat ../$reponame/malformed_exact.dat)"
expected_large="$(cat ../$reponame/malformed_large.dat)"
expected_xxl="$(cat ../$reponame/malformed_xxl.dat)"
actual_small="$(cat malformed_small.dat)"
actual_exact="$(cat malformed_exact.dat)"
actual_large="$(cat malformed_large.dat)"
actual_xxl="$(cat malformed_xxl.dat)"
[ "$expected_small" = "$actual_small" ]
[ "$expected_exact" = "$actual_exact" ]
[ "$expected_large" = "$actual_large" ]
[ "$expected_xxl" = "$actual_xxl" ]
popd >/dev/null
)
end_test
begin_test "empty pointers"
(
set -e
reponame="empty-pointers"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
git add .gitattributes
git commit -m "initial commit"
touch empty.dat
git \
-c "filter.lfs.process=" \
-c "filter.lfs.clean=cat" \
-c "filter.lfs.required=false" \
add empty.dat
git commit -m "add empty pointer"
[ "0" -eq "$(git cat-file -p :empty.dat | wc -c)" ]
[ "0" -eq "$(wc -c < empty.dat)" ]
git push origin main
pushd .. >/dev/null
clone_repo "$reponame" "$reponame-assert"
[ "0" -eq "$(grep -c "empty.dat" clone.log)" ]
[ "0" -eq "$(git cat-file -p :empty.dat | wc -c)" ]
[ "0" -eq "$(wc -c < empty.dat)" ]
popd >/dev/null
)
end_test