127 lines
2.8 KiB
Bash
Executable File
127 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
cd "$DIR"/.. || exit
|
|
|
|
source ./_reformat-common.bash
|
|
|
|
setUp() {
|
|
cd "$DIR"/.. || exit
|
|
unset PROJECT_ROOT
|
|
unset WF_ROOT
|
|
}
|
|
|
|
testProjectRoot001() {
|
|
dir=$(mktemp -d --tmpdir would-reformat-testProjectRoot001.XXXXXX)
|
|
cd "$dir" || exit
|
|
git init >/dev/null 2>&1
|
|
|
|
echo 'abc123' >random-file
|
|
|
|
pr=$(project_root random-file)
|
|
|
|
assertEquals "$dir" "$pr"
|
|
}
|
|
|
|
# This won't work (yet) because our only method of determining a
|
|
# project root is to ask git what it thinks.
|
|
testProjectRoot002() {
|
|
dir=$(mktemp -d --tmpdir would-reformat-testProjectRoot001.XXXXXX)
|
|
cd "$dir" || exit
|
|
|
|
echo 'abc123' >random-file
|
|
|
|
pr=$(project_root random-file)
|
|
|
|
assertEquals "" "$pr"
|
|
}
|
|
|
|
testResolveSymlink001() {
|
|
d1=$(mktemp -d --tmpdir targetdir.XXXXX)
|
|
expected="$d1/target"
|
|
touch "$expected"
|
|
|
|
d2=$(mktemp -d --tmpdir linkdir.XXXXX)
|
|
link="$d2"/link
|
|
ln -s "$d1"/target "$link"
|
|
|
|
resolved=$(resolve_symlink "$link")
|
|
|
|
assertEquals "$expected" "$resolved"
|
|
}
|
|
|
|
# This test is ugly but there's no obvious way to make it
|
|
# better without making it entirely tautological.
|
|
testNoramlizeDirOfFile001() {
|
|
input="$DIR"/../install.sh
|
|
|
|
expected="$DIR/.."
|
|
|
|
out=$(normalize_dir_of_file "$input")
|
|
|
|
assertEquals "$expected" "$out/tests/.."
|
|
}
|
|
|
|
testWfRoot001() {
|
|
expected=$(normalize_dir_of_file "$DIR/../install.sh")
|
|
|
|
dir=$(mktemp -d --tmpdir would-reformat-testProjectRoot001.XXXXXX)
|
|
cd "$dir" || exit
|
|
git init >/dev/null 2>&1
|
|
"$DIR"/../install.sh 2>&2 >/dev/null
|
|
|
|
got=$(wf_root)
|
|
|
|
assertEquals "$expected" "$got"
|
|
}
|
|
|
|
testWfRoot002() {
|
|
expected=$(normalize_dir_of_file "$DIR/../install.sh")
|
|
|
|
export WF_ROOT="$expected"
|
|
|
|
got=$(wf_root)
|
|
|
|
assertEquals "$expected" "$got"
|
|
}
|
|
|
|
testNoCustomSniffer001() {
|
|
dir=$(mktemp -d --tmpdir would-reformat-testProjectRoot001.XXXXXX)
|
|
cd "$dir" || exit
|
|
git init >/dev/null 2>&1
|
|
"$DIR"/../install.sh 2>&2 >/dev/null
|
|
|
|
touch perl-file.pl
|
|
touch typescript-file.ts
|
|
|
|
out1=$(sniff_file_type "$(pwd)"/perl-file.pl)
|
|
out2=$(sniff_file_type "$(pwd)"/typescript-file.ts)
|
|
|
|
assertEquals "perl" "$out1"
|
|
assertEquals "typescript" "$out2"
|
|
}
|
|
|
|
testCustomSniffer001() {
|
|
dir=$(mktemp -d --tmpdir would-reformat-testProjectRoot001.XXXXXX)
|
|
cd "$dir" || exit
|
|
git init >/dev/null 2>&1
|
|
"$DIR"/../install.sh 2>&2 >/dev/null
|
|
|
|
mkdir -p .would-reformat || exit 1
|
|
cp "$(wf_root)"/examples/custom-sniffer ./.would-reformat/custom-sniffer || exit 1
|
|
chmod +x ./.would-reformat/custom-sniffer || exit 1
|
|
|
|
touch prolog-file.pl
|
|
touch qt-translation-file.ts
|
|
|
|
out1=$(sniff_file_type "$(pwd)"/prolog-file.pl)
|
|
out2=$(sniff_file_type "$(pwd)"/qt-translation-file.ts)
|
|
|
|
assertEquals "prolog" "$out1"
|
|
assertEquals "qt-translation" "$out2"
|
|
}
|
|
|
|
# shellcheck disable=SC1091
|
|
source shunit2
|