this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

test: Add a test script against the official tools

+223
+3
.gitignore
··· 13 13 14 14 # task files for tracking already run commands 15 15 /.task 16 + 17 + # Local cache files for testing 18 + /.cache
+3
Taskfile.yml
··· 60 60 commit: 61 61 desc: Commit changes using custom script 62 62 cmd: "{{.BIN}}/commit.sh" 63 + test:full: 64 + desc: Run comparisons against official tools 65 + cmd: "{{.BIN}}/test.sh {{.CLI_ARGS}}"
+209
bin/test.sh
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + 4 + # Test functionality of cmprss by comparing it with the official tools 5 + 6 + CACHE_DIR="${PRJ_ROOT}/.cache" 7 + 8 + # Create a tmp directory and cd into it 9 + tmpdir() { 10 + mkdir -p "$CACHE_DIR" 11 + local dir=$(mktemp --directory --tmpdir="$CACHE_DIR") 12 + cd "$dir" 13 + } 14 + 15 + # Compare the two files/directories and exit with an error if they are different 16 + compare() { 17 + local file1="$1" 18 + local file2="$2" 19 + if ! diff -qr "$file1" "$file2" >/dev/null; then 20 + echo "Diff Detected: $file1 $file2" 21 + exit 1 22 + fi 23 + } 24 + 25 + # Compare the two archive sizes to check if they are similar 26 + # TODO: This doesn't work anywhere in the file because we're compressing random data 27 + # So the algos will always fail to compress things very well 28 + compare_size() { 29 + local file1="$1" 30 + local file2="$2" 31 + # Use $3 as the max difference or 100 bytes 32 + local max_diff=${3:-100} 33 + local size1=$(stat -c %s "$file1") 34 + local size2=$(stat -c %s "$file2") 35 + if [ $((size1 - size2)) -gt $max_diff ]; then 36 + echo "Size difference too large: $file1:$size1 $file2:$size2" 37 + exit 1 38 + fi 39 + } 40 + 41 + # Create a random file with the given size 42 + random_file() { 43 + local size="$1" 44 + local file="$2" 45 + dd if=/dev/urandom of="$file" bs=1 count="$size" 2>/dev/null 46 + } 47 + 48 + # Create a random directory with the given size 49 + random_dir() { 50 + local size="$1" 51 + local dir="$2" 52 + mkdir -p "$dir" 53 + for i in $(seq 1 "$size"); do 54 + random_file 1024 "$dir/$i" 55 + done 56 + } 57 + 58 + # Run cmprss using cargo to test the current version 59 + cmprss() { 60 + cargo run --release --quiet -- "$@" 61 + } 62 + 63 + test_tar() { 64 + tmpdir 65 + echo "Testing tar in $PWD" 66 + echo "Creating random data" 67 + random_dir 100 dir 68 + echo "Compressing with tar and cmprss" 69 + tar -cf tar_dir.tar dir 70 + cmprss tar dir cmprss_dir.tar 71 + # Compare the two archives 72 + # We don't care if the archives are slightly different, just that they decompress the same 73 + #compare tar_dir.tar cmprss_dir.tar 74 + # Decompress the 4 variations 75 + echo "Decompressing" 76 + mkdir -p tar_tar 77 + cd tar_tar 78 + tar -xf ../tar_dir.tar 79 + cd .. 80 + mkdir -p tar_cmprss 81 + cd tar_cmprss 82 + cmprss tar --extract ../tar_dir.tar 83 + cd .. 84 + mkdir -p cmprss_tar 85 + cd cmprss_tar 86 + tar -xf ../cmprss_dir.tar 87 + cd .. 88 + mkdir -p cmprss_cmprss 89 + cd cmprss_cmprss 90 + cmprss tar --extract ../cmprss_dir.tar 91 + cd .. 92 + 93 + echo "Comparing the decompressed files" 94 + compare dir tar_tar/dir 95 + compare dir tar_cmprss/dir 96 + compare dir cmprss_tar/dir 97 + compare dir cmprss_cmprss/dir 98 + echo "No errors detected" 99 + } 100 + 101 + # Test gzip using the provided compression level 102 + test_gzip_level() { 103 + tmpdir 104 + echo "Testing gzip level $1 in $PWD" 105 + echo "Creating random data" 106 + random_file 1000000 file 107 + echo "Compressing with gzip and cmprss" 108 + gzip -$1 -c file >gzip_file.gz 109 + cmprss gzip --level $1 file cmprss_file.gz 110 + # Compare the two archives 111 + # The archives may have slight variations (versioning or whatever) so we 112 + # only compare the sizes to make sure they are similar 113 + compare_size gzip_file.gz cmprss_file.gz 114 + # Decompress the 4 variations 115 + echo "Decompressing" 116 + gzip -c -d gzip_file.gz >gzip_gzip 117 + gzip -c -d cmprss_file.gz >cmprss_gzip 118 + cmprss gzip --extract cmprss_file.gz cmprss_cmprss 119 + cmprss gzip --extract gzip_file.gz gzip_cmprss 120 + echo "Comparing the decompressed files" 121 + compare file gzip_gzip 122 + compare file gzip_cmprss 123 + compare file cmprss_cmprss 124 + compare file cmprss_gzip 125 + echo "No errors detected" 126 + } 127 + 128 + test_gzip() { 129 + test_gzip_level 1 130 + test_gzip_level 6 # Default 131 + test_gzip_level 9 132 + } 133 + 134 + # Test xz using the provided compression level 135 + test_xz_level() { 136 + tmpdir 137 + echo "Testing xz level $1 in $PWD" 138 + echo "Creating random data" 139 + random_file 1000000 file 140 + echo "Compressing with xz and cmprss" 141 + xz -$1 --stdout file >xz_file.xz 142 + cmprss xz --level $1 file cmprss_file.xz --progress=off 143 + # Compare the two archives 144 + # The archives may have slight variations (versioning or whatever) so we 145 + # only compare the sizes to make sure they are similar 146 + compare_size xz_file.xz cmprss_file.xz 147 + # Decompress the 4 variations 148 + echo "Decompressing" 149 + xz --stdout --decompress xz_file.xz >xz_xz 150 + xz --stdout --decompress cmprss_file.xz >xz_cmprss 151 + cmprss xz --extract cmprss_file.xz cmprss_cmprss --progress=off 152 + cmprss xz --extract xz_file.xz cmprss_xz --progress=off 153 + echo "Comparing the decompressed files" 154 + compare file xz_xz 155 + compare file xz_cmprss 156 + compare file cmprss_cmprss 157 + compare file cmprss_xz 158 + echo "No errors detected" 159 + } 160 + 161 + test_xz() { 162 + test_xz_level 0 # No compression 163 + test_xz_level 1 164 + test_xz_level 6 # Default 165 + test_xz_level 9 166 + } 167 + 168 + # Test bzip2 using the provided compression level 169 + test_bzip2_level() { 170 + tmpdir 171 + echo "Testing bzip2 level $1 in $PWD" 172 + echo "Creating random data" 173 + random_file 1000000 file 174 + echo "Compressing with bzip2 and cmprss" 175 + bzip2 -$1 --stdout file >bzip2_file.bz2 176 + cmprss bzip2 --level $1 file cmprss_file.bz2 --progress=off 177 + # Compare the two archives 178 + # The archives may have slight variations (versioning or whatever) so we 179 + # only compare the sizes to make sure they are similar 180 + compare_size bzip2_file.bz2 cmprss_file.bz2 181 + # Decompress the 4 variations 182 + echo "Decompressing" 183 + bzip2 --stdout --decompress bzip2_file.bz2 >bzip2_bzip2 184 + bzip2 --stdout --decompress cmprss_file.bz2 >cmprss_bzip2 185 + cmprss bzip2 --extract cmprss_file.bz2 cmprss_cmprss --progress=off 186 + cmprss bzip2 --extract bzip2_file.bz2 bzip2_cmprss --progress=off 187 + echo "Comparing the decompressed files" 188 + compare file bzip2_bzip2 189 + compare file bzip2_cmprss 190 + compare file cmprss_cmprss 191 + compare file cmprss_bzip2 192 + echo "No errors detected" 193 + } 194 + 195 + test_bzip2() { 196 + test_bzip2_level 1 197 + test_bzip2_level 6 198 + test_bzip2_level 9 # Default 199 + } 200 + 201 + # Run all the tests if no arguments are given 202 + if [ $# -eq 0 ]; then 203 + set -- tar gzip xz bzip2 204 + fi 205 + 206 + # Run the tests given on the command line 207 + for test in "$@"; do 208 + test_"$test" 209 + done
+8
flake.nix
··· 148 148 149 149 # Code coverage 150 150 cargo-tarpaulin 151 + 152 + # For running tests 153 + diffutils 154 + # Official tools 155 + bzip2 156 + gnutar 157 + gzip 158 + xz 151 159 ]; 152 160 153 161 # Many tools read this to find the sources for rust stdlib