tests(trinitry): Add some sort of fuzzing

This commit is contained in:
Benedikt Peetz 2023-11-01 13:19:22 +01:00
parent 091d77089b
commit 43d991871f
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
2 changed files with 1453 additions and 0 deletions

1365
trinitry/src/tests.rs Normal file

File diff suppressed because it is too large Load Diff

88
trinitry/update.sh Executable file
View File

@ -0,0 +1,88 @@
#!/usr/bin/env sh
# Library {{{
mktmp() {
ensure_tmp_dir
mktemp -p "$LIB_TEMP_DIR_FOR_SCRIPT"
}
ensure_tmp_dir() {
if ! [ -d "$LIB_TEMP_DIR_FOR_SCRIPT" ]; then
LIB_TEMP_DIR_FOR_SCRIPT="$(mktemp -d)"
export LIB_TEMP_DIR_FOR_SCRIPT
fi
}
remove_tmp_dir() {
# The test is here because some scripts still delete this on their own
if [ -d "$LIB_TEMP_DIR_FOR_SCRIPT" ]; then
rm -r "$LIB_TEMP_DIR_FOR_SCRIPT"
fi
}
trap remove_tmp_dir EXIT
ensure_tmp_dir # ensure that the variable has been set, even in subshells
# }}}
tmp="$(mktmp)"
curl https://raw.githubusercontent.com/minimaxir/big-list-of-naughty-strings/master/blns.txt |
awk '!/^#/' |
awk '!/^[\s\t]*$/' |
awk -v s="'" '!/.*s.*/' |
# This entry contains duplicated spaces, just ignore it
awk '!/Power/' |
iconv -c -f utf-8 -t ascii \
>"$tmp"
counter=0
cat <<EOF
// DO NOT EDIT
// This file is automatically generated by the 'update.sh' file, with data from:
// https://raw.githubusercontent.com/minimaxir/big-list-of-naughty-strings/master/blns.txt
#[cfg(test)]
mod test {
use crate::Trinitry;
EOF
while read -r name; do
tmp2="$(mktmp)"
printf "%s" "$name" >"$tmp2"
if rg '^[A-Za-z0-9_.-]+$' "$tmp2" -q; then
cat <<EOF
#[test]
fn parse_$counter() {
let p = Trinitry::new(r##"$name"##).unwrap_or_else(|e| {
panic!("{}", e);
});
assert_eq!(r##"$name"##, &p.to_string());
}
EOF
elif rg '^[A-Za-z0-9_.-]+ [A-Za-z0-9_.(){}<>?!+^@&*~|=,/\\ -]*$' "$tmp2" -q; then
cat <<EOF
#[test]
fn parse_$counter() {
let p = Trinitry::new(r##"$name"##).unwrap_or_else(|e| {
panic!("{}", e);
});
assert_eq!(r##"$name"##, &p.to_string());
}
EOF
else
cat <<EOF
#[test]
fn parse_$counter() {
let p = Trinitry::new(r##"$name"##);
assert!(p.is_err());
}
EOF
fi
counter=$((counter + 1))
done <"$tmp"
cat <<EOF
}
EOF
# vim: ft=sh