mirror of
https://github.com/theryangeary/choose
synced 2024-11-23 03:13:04 +00:00
Reassign exit codes and clean up e2e_test
0 - Success 1 - Argument parsing error 2 - Regex compilation error
This commit is contained in:
parent
5b5fa0ed7a
commit
dfe4c2cad0
2 changed files with 23 additions and 18 deletions
|
@ -32,19 +32,19 @@ impl Config {
|
|||
}) {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
// Exit code of 1 means failed to compile field_separator regex
|
||||
// Exit code of 2 means failed to compile field_separator regex
|
||||
match e {
|
||||
regex::Error::Syntax(e) => {
|
||||
eprintln!("Syntax error compiling regular expression: {}", e);
|
||||
process::exit(1);
|
||||
process::exit(2);
|
||||
}
|
||||
regex::Error::CompiledTooBig(e) => {
|
||||
eprintln!("Compiled regular expression too big: compiled size cannot exceed {} bytes", e);
|
||||
process::exit(1);
|
||||
process::exit(2);
|
||||
}
|
||||
_ => {
|
||||
eprintln!("Error compiling regular expression: {}", e);
|
||||
process::exit(1);
|
||||
process::exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,30 +4,35 @@ set -e
|
|||
test_dir="test"
|
||||
orig_dir="$(pwd)"
|
||||
cd "$(git rev-parse --show-toplevel)"
|
||||
cargo build
|
||||
|
||||
# basic functionality
|
||||
diff -w <(cargo run -- 0:1 -i ${test_dir}/lorem.txt) <(cat "${test_dir}/choose_0:1.txt")
|
||||
diff -w <(cargo run -- 0 3 -i ${test_dir}/lorem.txt) <(cat "${test_dir}/choose_0_3.txt")
|
||||
diff -w <(cargo run -- :1 -i ${test_dir}/lorem.txt) <(cat "${test_dir}/choose_:1.txt")
|
||||
diff -w <(cargo run -- 9 3 -i ${test_dir}/lorem.txt) <(cat "${test_dir}/choose_9_3.txt")
|
||||
diff -w <(cargo run -- 9 -i ${test_dir}/lorem.txt) <(cat "${test_dir}/choose_9.txt")
|
||||
diff -w <(cargo run -- 12 -i ${test_dir}/lorem.txt) <(cat "${test_dir}/choose_12.txt")
|
||||
diff -w <(cargo run -- 4:2 -i ${test_dir}/lorem.txt) <(cat "${test_dir}/choose_4:2.txt")
|
||||
diff -w <(cargo run -- 0:1 -i ${test_dir}/lorem.txt 2>/dev/null) <(cat "${test_dir}/choose_0:1.txt")
|
||||
diff -w <(cargo run -- 0 3 -i ${test_dir}/lorem.txt 2>/dev/null) <(cat "${test_dir}/choose_0_3.txt")
|
||||
diff -w <(cargo run -- :1 -i ${test_dir}/lorem.txt 2>/dev/null) <(cat "${test_dir}/choose_:1.txt")
|
||||
diff -w <(cargo run -- 9 3 -i ${test_dir}/lorem.txt 2>/dev/null) <(cat "${test_dir}/choose_9_3.txt")
|
||||
diff -w <(cargo run -- 9 -i ${test_dir}/lorem.txt 2>/dev/null) <(cat "${test_dir}/choose_9.txt")
|
||||
diff -w <(cargo run -- 12 -i ${test_dir}/lorem.txt 2>/dev/null) <(cat "${test_dir}/choose_12.txt")
|
||||
diff -w <(cargo run -- 4:2 -i ${test_dir}/lorem.txt 2>/dev/null) <(cat "${test_dir}/choose_4:2.txt")
|
||||
# add tests for different delimiters
|
||||
# add tests using piping
|
||||
|
||||
set +e
|
||||
|
||||
# test failure to parse arguments
|
||||
cargo run -- d:i -i ${test_dir}/lorem.txt >/dev/null
|
||||
cargo run -- d:i -i ${test_dir}/lorem.txt >&/dev/null
|
||||
r=$?
|
||||
if [ $r -ne 2 ]; then
|
||||
echo "Failed to return error code 2 on failure to parse arguments"
|
||||
else
|
||||
echo "Success"
|
||||
if [ $r -ne 1 ]; then
|
||||
echo "Failed to return 1 on failure to parse arguments"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cargo test
|
||||
cargo run -- 3 -f "[[]" -i ${test_dir}/lorem.txt >&/dev/null
|
||||
r=$?
|
||||
if [ $r -ne 2 ]; then
|
||||
echo "Failed to return 2 on regex compile error"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd $orig_dir
|
||||
|
||||
printf "\033[1;32mAll tests passed\033[0m\n"
|
||||
|
|
Loading…
Reference in a new issue