Skip to content

Commit 9b557cb

Browse files
committed
Consolidate sanoid-portable tests into a single script
1 parent 93bd238 commit 9b557cb

File tree

4 files changed

+76
-55
lines changed

4 files changed

+76
-55
lines changed

.github/workflows/build.yml

+11-25
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
1919
# Add a new binfmt entry that matches APE's (Actually Portable Executable)'s
2020
# magic number to avoid execution by Ubuntu's built-in "MZ" binfmt
21-
# interpreter which "helpfully" tries to run the binary with WINE.
21+
# interpreter which "helpfully" tries to run the binary with Wine.
2222
sudo update-binfmts --install APE /bin/sh --magic MZqFpD
2323
2424
./build.sh
@@ -37,41 +37,27 @@ jobs:
3737
needs: build
3838
runs-on: ubuntu-latest
3939
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v4
4042
- name: Download sanoid-portable artifact
4143
uses: actions/download-artifact@v4
4244
with:
4345
name: ${{ needs.build.outputs.artifact_name }}
44-
- name: Test in Ubuntu
46+
- name: Test on Ubuntu
4547
run: |
4648
# Test on Ubuntu
4749
50+
# Add a new binfmt entry that matches APE's (Actually Portable Executable)'s
51+
# magic number to avoid execution by Ubuntu's built-in "MZ" binfmt
52+
# interpreter which "helpfully" tries to run the binary with Wine.
4853
sudo update-binfmts --install APE /bin/sh --magic MZqFpD
4954
50-
chmod +x sanoid-portable
51-
ln -s sanoid-portable sanoid
52-
ln -s sanoid-portable syncoid
53-
ln -s sanoid-portable findoid
54-
55-
./sanoid-portable -h
56-
./sanoid -h
57-
./syncoid -h
58-
./findoid -h
59-
60-
ls -lah
61-
62-
echo 'SHA-256 checksum:'
63-
sha256sum sanoid-portable
55+
./test.sh
6456
- name: Test in FreeBSD
6557
uses: vmactions/freebsd-vm@v1
6658
with:
6759
usesh: true
60+
prepare: |
61+
pkg install -y jq
6862
run: |
69-
./sanoid-portable -h
70-
./sanoid -h
71-
./syncoid -h
72-
./findoid -h
73-
74-
ls -lah
75-
76-
echo 'SHA-256 checksum:'
77-
sha256sum sanoid-portable
63+
./test.sh

build.sh

+2-25
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,9 @@ echo ''
7777
echo 'Build complete.'
7878
echo ''
7979

80-
stat sanoid-portable
80+
echo 'Testing...'
8181
echo ''
8282

83-
./sanoid-portable
84-
85-
# APPerl uses the invoking command name (argv[0]) to determine which internal script to run
86-
ln -s sanoid-portable sanoid
87-
ln -s sanoid-portable syncoid
88-
ln -s sanoid-portable findoid
89-
90-
./sanoid --version
91-
echo ''
92-
93-
echo 'Testing execution of sanoid...'
94-
./sanoid --help
95-
echo ''
96-
97-
echo 'Testing execution of syncoid...'
98-
./syncoid --help
99-
echo ''
100-
101-
echo 'Testing execution of findoid...'
102-
./findoid --help
103-
echo ''
104-
105-
echo 'SHA-256 checksum:'
106-
sha256sum sanoid-portable
83+
"${repo_root}/test.sh"
10784

10885
popd > /dev/null

sanoid-portable.pl

+2-5
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,5 @@
5858
exit 0;
5959
}
6060

61-
if ($print_help) {
62-
print "$all_versions\n";
63-
print $usage;
64-
exit 0;
65-
}
61+
print $usage;
62+
print "$all_versions\n";

test.sh

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env sh
2+
3+
set -eu
4+
5+
# Use the current directory by default
6+
output_dir=$(pwd)
7+
8+
# Optionally pass in the output directory
9+
# Usage: test.sh [output-directory]
10+
if [ $# -gt 0 ] && [ -n "${1}" ]; then
11+
output_dir=$(realpath "${1}")
12+
fi
13+
14+
sanoid_portable_path="${output_dir}/sanoid-portable"
15+
if [ ! -f "${sanoid_portable_path}" ]; then
16+
echo "Error: sanoid-portable does not exist at \"$(dirname "${sanoid_portable_path}")\"."
17+
exit 1
18+
fi
19+
20+
chmod +x "${output_dir}/sanoid-portable"
21+
$sanoid_portable_path --help
22+
23+
expected_sanoid_version=$(jq -r '.Sanoid' versions.json)
24+
expected_sanoid_portable_version="${expected_sanoid_version}-$(jq -r '.PackagingRevision' versions.json)"
25+
actual_sanoid_portable_version=$($sanoid_portable_path --version)
26+
27+
if [ "${actual_sanoid_portable_version}" != "${expected_sanoid_portable_version}" ]; then
28+
echo "Error: Expected sanoid-portable version \"${expected_sanoid_portable_version}\" but got \"${actual_sanoid_portable_version}\"."
29+
exit 1
30+
fi
31+
32+
for tool in sanoid syncoid findoid; do
33+
tool_path="${output_dir}/${tool}"
34+
35+
# APPerl uses the invoking command name (argv[0]) to determine which internal script to run
36+
ln -sf sanoid-portable "${tool_path}"
37+
38+
tool_version_output=$($tool_path --version | head -n 1)
39+
expected_version_output="/zip/bin/${tool} version ${expected_sanoid_version}"
40+
41+
if [ "${tool_version_output}" != "${expected_version_output}" ]; then
42+
echo $tool_version_output
43+
echo "Error: Expected \"${tool} --version\" output to be \"${expected_version_output}\" but got \"${tool_version_output}\"."
44+
exit 1
45+
fi
46+
47+
$tool_path --version
48+
$tool_path --help
49+
50+
if [ $? -ne 0 ]; then
51+
echo "Error: Command \"${tool_path} --help\" failed with exit code $?"
52+
exit $?
53+
fi
54+
done
55+
56+
ls -lah "${output_dir}"
57+
58+
echo ''
59+
60+
echo 'SHA-256 checksum:'
61+
sha256sum $sanoid_portable_path

0 commit comments

Comments
 (0)