commit 958b6e995ab87f2c3f528c667562367e08646e0a
parent a663e8ec55b90758d5412cd6e6342e0d25c3c538
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 31 Jan 2025 12:06:12 +0100
Test git-wad on tiny binaries
In addition to basic functionality, it should test a special case where
file contents are restored in the same second as repository cloning: git
should force the git-wad filter to be re-executed.
Diffstat:
3 files changed, 106 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -37,4 +37,8 @@ uninstall:
lint:
shellcheck -o all git-wad
+ shellcheck -o all test_tiny_bin.sh
mandoc -Wbase -Tlint git-wad.1
+
+test:
+ ./test_tiny_bin.sh 1> /dev/null 2>&1
diff --git a/README.md b/README.md
@@ -15,6 +15,10 @@ Git filters used to manage files based on their digest.
make install
+## Test
+
+ make test
+
## License
Copyright (C) 2023-2025 |Méso|Star> (contact@meso-star.com)
diff --git a/test_tiny_bin.sh b/test_tiny_bin.sh
@@ -0,0 +1,98 @@
+#!/bin/sh
+
+# Copyright (C) 2023-2025 |Méso|Star> (contact@meso-star.com)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+die()
+{
+ rm -rf "${tmpdir}" # cleanup temporary files
+ exit "${1:-1}" # return status code (default is 1)
+}
+
+git_wad="$(pwd)/git-wad"
+
+# Working directory
+tmpdir="$(mktemp -d "${TMPDIR:-/tmp}"/git_wad_test_XXXXXX)" || die "$?"
+repo="${tmpdir}/tiny_bin"
+
+# Configure signal processing
+trap "die 1" TERM INT
+
+# Create the bare repository
+mkdir -p "${repo}.git"
+git init --bare "${repo}.git"
+
+# Create the repository content to be managed by git-wad
+mkdir -p "${repo}_ref"
+dd if=/dev/random of="${repo}_ref/file0.bin" bs=1024 count=1
+dd if=/dev/random of="${repo}_ref/file1.bin" bs=1024 count=2
+dd if=/dev/random of="${repo}_ref/file2.bin" bs=1024 count=3
+dd if=/dev/random of="${repo}_ref/file3.bin" bs=1024 count=4
+dd if=/dev/zero of="${repo}_ref/file4.bin" bs=1024 count=5
+
+# Add a README file to be managed by git
+printf 'Repository with small binaries tracked by git-wad' \
+ > "${repo}_ref/README"
+
+# Use git-wad to manage binary files
+printf '*.bin filter=wad' > "${repo}_ref/.gitattributes"
+
+# Configure the directory as a git working directory, commit its
+# content and push it to the remote repository
+cd "${repo}_ref"
+git init
+git config --local user.name "John Doe"
+git config --local user.email "john@doe.com"
+"${git_wad}" init
+git add ./*.bin README .gitattributes
+git commit -m "Test small binaries"
+git remote add origin "file://${repo}.git"
+git push origin master
+"${git_wad}" push
+
+# Clone a fresh git working directory from the remote
+cd "${tmpdir}"
+git clone "file://${repo}.git"
+
+# Check that files managed by git-wad have not yet been restored,
+# whereas normal files are the same as the originals, i.e. they are not
+# actually managed by git and not git-wad.
+! diff "${repo}/file0.bin" "${repo}_ref/file0.bin" || die $?
+! diff "${repo}/file1.bin" "${repo}_ref/file1.bin" || die $?
+! diff "${repo}/file2.bin" "${repo}_ref/file2.bin" || die $?
+! diff "${repo}/file3.bin" "${repo}_ref/file3.bin" || die $?
+! diff "${repo}/file4.bin" "${repo}_ref/file4.bin" || die $?
+diff "${repo}/README" "${repo}_ref/README"
+diff "${repo}/.gitattributes" "${repo}_ref/.gitattributes"
+
+# Restore the files managed by git-wad
+cd "${repo}"
+"${git_wad}" init
+"${git_wad}" pull
+"${git_wad}" status
+
+# Check that, once restored, the files managed by git-wad are the same
+# as the original files.
+diff "${repo}/file0.bin" "${repo}_ref/file0.bin"
+diff "${repo}/file1.bin" "${repo}_ref/file1.bin"
+diff "${repo}/file2.bin" "${repo}_ref/file2.bin"
+diff "${repo}/file3.bin" "${repo}_ref/file3.bin"
+diff "${repo}/file4.bin" "${repo}_ref/file4.bin"
+diff "${repo}/README" "${repo}_ref/README"
+diff "${repo}/.gitattributes" "${repo}_ref/.gitattributes"
+
+die 0