Skip to content

Commit

Permalink
t: pipe data to base64 to be compatible with macOS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chrisd8088 committed Jan 11, 2024
1 parent ad64c6c commit fef4c0f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions t/t-clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ begin_test "clean stdin"
git init "$reponame"
cd "$reponame"

base64 /dev/urandom | head -c 1024 > small.dat
base64 /dev/urandom | head -c 2048 > large.dat
base64 < /dev/urandom | head -c 1024 > small.dat
base64 < /dev/urandom | head -c 2048 > large.dat

expected_small="$(calc_oid_file "small.dat")"
expected_large="$(calc_oid_file "large.dat")"
Expand Down
2 changes: 1 addition & 1 deletion t/t-fsck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ create_invalid_pointers() {
ext="${2:-dat}"

git cat-file blob ":$valid" | awk '{ sub(/$/, "\r"); print }' >"crlf.$ext"
base64 /dev/urandom | head -c 1025 >"large.$ext"
base64 < /dev/urandom | head -c 1025 >"large.$ext"
git \
-c "filter.lfs.process=" \
-c "filter.lfs.clean=cat" \
Expand Down
8 changes: 4 additions & 4 deletions t/t-malformed-pointers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ begin_test "malformed pointers"
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
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=" \
Expand Down

0 comments on commit fef4c0f

Please sign in to comment.