2020-04-06 13:55:57 +02:00
|
|
|
HAS_RIPGREP=false
|
|
|
|
|
2020-02-20 05:49:20 +01:00
|
|
|
setup() {
|
|
|
|
use_shim 'batgrep'
|
2021-04-09 10:12:36 +02:00
|
|
|
|
|
|
|
unset BAT_STYLE
|
2020-04-06 13:55:57 +02:00
|
|
|
|
|
|
|
if command -v rg &>/dev/null; then
|
|
|
|
HAS_RIPGREP=true
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
require_rg() {
|
|
|
|
if ! "$HAS_RIPGREP"; then
|
|
|
|
skip "Ripgrep (rg) is not installed."
|
|
|
|
fi
|
2020-02-20 05:49:20 +01:00
|
|
|
}
|
|
|
|
|
2020-04-08 11:56:17 +02:00
|
|
|
test:version() {
|
|
|
|
description "Test 'batgrep --version'"
|
|
|
|
snapshot stdout
|
|
|
|
snapshot stderr
|
2020-04-08 12:11:56 +02:00
|
|
|
|
2020-04-27 10:22:22 +02:00
|
|
|
batgrep --version | awk 'FNR <= 1 { print $1 }'
|
2020-04-08 12:11:56 +02:00
|
|
|
batgrep --version | awk 'p{print} /^$/ { p=1 }'
|
2020-04-08 11:56:17 +02:00
|
|
|
}
|
|
|
|
|
2020-02-20 05:49:20 +01:00
|
|
|
test:regular_file() {
|
|
|
|
description "Search for a pattern in a regular file."
|
|
|
|
snapshot stdout
|
|
|
|
snapshot stderr
|
|
|
|
|
2020-04-06 13:55:57 +02:00
|
|
|
require_rg
|
|
|
|
|
2020-02-20 05:49:20 +01:00
|
|
|
batgrep "ca" file.txt
|
|
|
|
}
|
|
|
|
|
|
|
|
test:symlink_file() {
|
|
|
|
description "Search for a pattern in a symlinked file."
|
|
|
|
snapshot stdout
|
|
|
|
snapshot stderr
|
|
|
|
|
2020-04-06 13:55:57 +02:00
|
|
|
require_rg
|
|
|
|
|
2020-02-20 05:49:20 +01:00
|
|
|
batgrep "ca" link.txt
|
|
|
|
}
|
|
|
|
|
|
|
|
test:output_with_color() {
|
|
|
|
description "Snapshot test for colored output."
|
|
|
|
snapshot stdout
|
|
|
|
snapshot stderr
|
|
|
|
|
2020-04-06 13:55:57 +02:00
|
|
|
require_rg
|
|
|
|
|
2020-02-20 05:49:20 +01:00
|
|
|
batgrep "ca" file.txt --color=always
|
|
|
|
}
|
|
|
|
|
|
|
|
test:output_without_color() {
|
|
|
|
description "Snapshot test for colored output."
|
|
|
|
snapshot stdout
|
|
|
|
snapshot stderr
|
|
|
|
|
2020-04-06 13:55:57 +02:00
|
|
|
require_rg
|
|
|
|
|
2020-02-20 05:49:20 +01:00
|
|
|
batgrep "ca" file.txt --color=never
|
|
|
|
}
|
|
|
|
|
|
|
|
test:search_regex() {
|
|
|
|
description "Search for a regex pattern."
|
|
|
|
snapshot stdout
|
|
|
|
snapshot stderr
|
|
|
|
|
2020-04-06 13:55:57 +02:00
|
|
|
require_rg
|
|
|
|
|
2020-02-20 05:49:20 +01:00
|
|
|
batgrep "^[cb]" file.txt
|
|
|
|
}
|
|
|
|
|
|
|
|
test:search_fixed() {
|
|
|
|
description "Search for fixed strings."
|
|
|
|
snapshot stdout
|
|
|
|
snapshot stderr
|
|
|
|
|
2020-04-06 13:55:57 +02:00
|
|
|
require_rg
|
|
|
|
|
2020-02-20 05:49:20 +01:00
|
|
|
batgrep --fixed-strings '$' file.txt
|
|
|
|
}
|
|
|
|
|
|
|
|
test:option_context() {
|
|
|
|
description "Search and use the context option."
|
|
|
|
snapshot stdout
|
|
|
|
snapshot stderr
|
|
|
|
|
2020-04-06 13:55:57 +02:00
|
|
|
require_rg
|
|
|
|
|
2020-02-20 05:49:20 +01:00
|
|
|
batgrep -C 0 '\$' file.txt
|
|
|
|
}
|
2020-10-29 03:04:52 +01:00
|
|
|
|
|
|
|
test:search_from_stdin() {
|
|
|
|
description "Should be able to search through stdin."
|
|
|
|
snapshot stdout
|
|
|
|
snapshot stderr
|
|
|
|
|
|
|
|
require_rg
|
|
|
|
|
|
|
|
cat file.txt | batgrep "^ca"
|
|
|
|
}
|
2021-04-09 10:12:36 +02:00
|
|
|
|
|
|
|
test:respects_bat_style() {
|
|
|
|
description "Should respect the BAT_STYLE variable."
|
|
|
|
snapshot stdout
|
|
|
|
snapshot stderr
|
|
|
|
|
|
|
|
require_rg
|
|
|
|
|
|
|
|
BAT_STYLE="grid" batgrep "ca" file.txt --color=always
|
|
|
|
}
|
2021-08-29 11:03:09 +02:00
|
|
|
|
|
|
|
test:output_without_separator() {
|
|
|
|
description "Snapshot test for output without separator"
|
|
|
|
snapshot stdout
|
|
|
|
snapshot stderr
|
|
|
|
|
|
|
|
require_rg
|
|
|
|
|
|
|
|
batgrep "ca" file.txt --no-separator --color=always
|
|
|
|
}
|
2023-03-21 07:06:07 +01:00
|
|
|
|
|
|
|
test:sanity_rg_works() {
|
|
|
|
description "Ensure the ripgrep executable works"
|
|
|
|
|
|
|
|
require_rg
|
|
|
|
|
|
|
|
rg --version
|
|
|
|
rg "ca" file.txt | grep "ca" || fail "Ripgrep executable not working."
|
|
|
|
}
|
|
|
|
|