mirror of
https://github.com/sstephenson/bats.git
synced 2024-11-17 11:42:33 +01:00
exec-test: Use printf -v
in bats_extract_line
Also replaces `sed` invocation with a `while` loop, saving a subprocess.
This commit is contained in:
parent
698fa766a3
commit
d294689bdd
|
@ -157,13 +157,12 @@ bats_print_failed_command() {
|
||||||
local status="$2"
|
local status="$2"
|
||||||
local filename
|
local filename
|
||||||
local lineno
|
local lineno
|
||||||
|
local failed_line
|
||||||
|
local failed_command
|
||||||
|
|
||||||
bats_frame_filename "$frame" 'filename'
|
bats_frame_filename "$frame" 'filename'
|
||||||
bats_frame_lineno "$frame" 'lineno'
|
bats_frame_lineno "$frame" 'lineno'
|
||||||
|
bats_extract_line "$filename" "$lineno" 'failed_line'
|
||||||
local failed_line="$(bats_extract_line "$filename" "$lineno")"
|
|
||||||
local failed_command
|
|
||||||
|
|
||||||
bats_strip_string "$failed_line" 'failed_command'
|
bats_strip_string "$failed_line" 'failed_command'
|
||||||
printf '%s' "# \`${failed_command}' "
|
printf '%s' "# \`${failed_command}' "
|
||||||
|
|
||||||
|
@ -194,9 +193,15 @@ bats_frame_filename() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bats_extract_line() {
|
bats_extract_line() {
|
||||||
local filename="$1"
|
local __bats_extract_line_line
|
||||||
local lineno="$2"
|
local __bats_extract_line_index='0'
|
||||||
sed -n "${lineno}p" "$filename"
|
|
||||||
|
while IFS= read -r __bats_extract_line_line; do
|
||||||
|
if [[ "$((++__bats_extract_line_index))" -eq "$2" ]]; then
|
||||||
|
printf -v "$3" '%s' "${__bats_extract_line_line%$'\r'}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done <"$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
bats_strip_string() {
|
bats_strip_string() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user