Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions shellkin
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
# This script was generated by bashly 1.4.0 (https://bashly.dev)
# This script was generated by bashly 2.0.0.rc1 (https://bashly.dev)
# Modifying it manually is not recommended

# :wrapper.bash3_bouncer
# :wrapper.bash_version_bouncer
if ((BASH_VERSINFO[0] < 4 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] < 2))); then
printf "bash version 4.2 or higher is required\n" >&2
exit 1
Expand Down Expand Up @@ -342,7 +342,7 @@ inspect_args() {
local k

if ((${#args[@]})); then
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | LC_ALL=C sort)
echo args:
for k in "${sorted_keys[@]}"; do
echo "- \${args[$k]} = ${args[$k]}"
Expand Down Expand Up @@ -1806,6 +1806,8 @@ step_run() {
local j
local step_type
local body
local capture_index
local capture_value
local -a tokens=()
local -a capture_indexes=()

Expand All @@ -1830,7 +1832,16 @@ step_run() {
fi

for j in "${!tokens[@]}"; do
printf -v "${tokens[$j]}" '%s' "${BASH_REMATCH[${capture_indexes[$j]}]}"
capture_index=${capture_indexes[$j]}
if [[ $capture_index == q* ]]; then
capture_index=${capture_index#q}
capture_value=${BASH_REMATCH[$capture_index]}
capture_value=${capture_value:1:-1}
else
capture_value=${BASH_REMATCH[$capture_index]}
fi

printf -v "${tokens[$j]}" '%s' "$capture_value"
export "${tokens[$j]}"
done

Expand Down Expand Up @@ -2220,7 +2231,6 @@ pattern_regex() {
local remainder=$pattern
local literal
local quote
local quote_group

while [[ $remainder =~ ^([^{}]*)\{([A-Za-z_][A-Za-z0-9_]*)\}(.*)$ ]]; do
literal=${BASH_REMATCH[1]}
Expand All @@ -2236,12 +2246,9 @@ pattern_regex() {
if [[ -n $quote ]]; then
literal=${literal%?}
remainder=${remainder#?}
((capture_index += 1))
quote_group=$capture_index

compiled+=$(_pattern_escape_literal "$literal")
compiled+='(['\''"])'
compiled+="(.+)\\$quote_group"
compiled+="('.+'|\".+\")"
((capture_index += 1))
continue
fi
Expand Down Expand Up @@ -2290,8 +2297,8 @@ pattern_capture_indexes() {

if [[ -n $quote ]]; then
remainder=${remainder#?}
((capture_index += 2))
indexes+=("$capture_index")
((capture_index += 1))
indexes+=("q$capture_index")
continue
fi

Expand Down Expand Up @@ -2835,9 +2842,13 @@ bashly_run() {
esac
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
# :command.start
# :command.start
start() {
command_line_args=("$@")
initialize
bashly_run "${command_line_args[@]}"
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
start "$@"
fi
13 changes: 12 additions & 1 deletion src/lib/step/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ step_run() {
local j
local step_type
local body
local capture_index
local capture_value
local -a tokens=()
local -a capture_indexes=()

Expand All @@ -49,7 +51,16 @@ step_run() {
fi

for j in "${!tokens[@]}"; do
printf -v "${tokens[$j]}" '%s' "${BASH_REMATCH[${capture_indexes[$j]}]}"
capture_index=${capture_indexes[$j]}
if [[ $capture_index == q* ]]; then
capture_index=${capture_index#q}
capture_value=${BASH_REMATCH[$capture_index]}
capture_value=${capture_value:1:-1}
else
capture_value=${BASH_REMATCH[$capture_index]}
fi

printf -v "${tokens[$j]}" '%s' "$capture_value"
export "${tokens[$j]}"
done

Expand Down
10 changes: 3 additions & 7 deletions src/lib/stepdef/pattern.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pattern_regex() {
local remainder=$pattern
local literal
local quote
local quote_group

while [[ $remainder =~ ^([^{}]*)\{([A-Za-z_][A-Za-z0-9_]*)\}(.*)$ ]]; do
literal=${BASH_REMATCH[1]}
Expand All @@ -22,12 +21,9 @@ pattern_regex() {
if [[ -n $quote ]]; then
literal=${literal%?}
remainder=${remainder#?}
((capture_index += 1))
quote_group=$capture_index

compiled+=$(_pattern_escape_literal "$literal")
compiled+='(['\''"])'
compiled+="(.+)\\$quote_group"
compiled+="('.+'|\".+\")"
((capture_index += 1))
continue
fi
Expand Down Expand Up @@ -78,8 +74,8 @@ pattern_capture_indexes() {

if [[ -n $quote ]]; then
remainder=${remainder#?}
((capture_index += 2))
indexes+=("$capture_index")
((capture_index += 1))
indexes+=("q$capture_index")
continue
fi

Expand Down
9 changes: 9 additions & 0 deletions test/lib/step/core.bats
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ teardown() {
[ "$STEP_RESULT" = "Something's wrong" ]
}

@test "step_run rejects mismatched quote delimiters" {
stepdef_parse "@Then the text should include '{text}'"
stepdef_register 'STEP_RESULT="$text"'

! step_run Then "the text should include 'mismatched\""

[ -z "$STEP_RESULT" ]
}

@test "step_run returns non-zero when no step definition matches" {
stepdef_parse "@When I run '{command}'"
stepdef_register 'run "$command"'
Expand Down
6 changes: 3 additions & 3 deletions test/lib/stepdef/files.bats
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ EOF
[ "${#STEPDEF_TYPES[@]}" -eq 2 ]
[ "${STEPDEF_TYPES[0]}" = "When" ]
[ "${STEPDEF_TYPES[1]}" = "Then" ]
[ "${STEPDEF_REGEXES[0]}" = "I run (['\"])(.+)\\1" ]
[ "${STEPDEF_CAPTURE_INDEXES_LIST[0]}" = "2" ]
[ "${STEPDEF_CAPTURE_INDEXES_LIST[1]}" = "2" ]
[ "${STEPDEF_REGEXES[0]}" = "I run ('.+'|\".+\")" ]
[ "${STEPDEF_CAPTURE_INDEXES_LIST[0]}" = "q1" ]
[ "${STEPDEF_CAPTURE_INDEXES_LIST[1]}" = "q1" ]
}

@test "stepdefs_file_parse preserves multi-line step bodies" {
Expand Down
12 changes: 6 additions & 6 deletions test/lib/stepdef/parse.bats
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ teardown() {
@test "stepdef_parse derives the regex from the template" {
stepdef_parse "@Then the file '{path}' should exist"

[ "$STEPDEF_REGEX" = "the file (['\"])(.+)\\1 should exist" ]
[ "$STEPDEF_CAPTURE_INDEXES" = "2" ]
[ "$STEPDEF_REGEX" = "the file ('.+'|\".+\") should exist" ]
[ "$STEPDEF_CAPTURE_INDEXES" = "q1" ]
}

@test "stepdef_parse returns token names in declaration order" {
Expand Down Expand Up @@ -136,9 +136,9 @@ teardown() {

[ "${STEPDEF_TYPES[0]}" = "When" ]
[ "${STEPDEF_PATTERNS[0]}" = "I run '{command}'" ]
[ "${STEPDEF_REGEXES[0]}" = "I run (['\"])(.+)\\1" ]
[ "${STEPDEF_REGEXES[0]}" = "I run ('.+'|\".+\")" ]
[ "${STEPDEF_TOKENS_LIST[0]}" = "command" ]
[ "${STEPDEF_CAPTURE_INDEXES_LIST[0]}" = "2" ]
[ "${STEPDEF_CAPTURE_INDEXES_LIST[0]}" = "q1" ]
[ "${STEPDEF_BODIES[0]}" = 'run "$command"' ]
}

Expand All @@ -154,6 +154,6 @@ teardown() {
[ "${STEPDEF_TYPES[1]}" = "Then" ]
[ "${STEPDEF_TOKENS_LIST[0]}" = "directory" ]
[ "${STEPDEF_TOKENS_LIST[1]}" = "path" ]
[ "${STEPDEF_CAPTURE_INDEXES_LIST[0]}" = "2" ]
[ "${STEPDEF_CAPTURE_INDEXES_LIST[1]}" = "2" ]
[ "${STEPDEF_CAPTURE_INDEXES_LIST[0]}" = "q1" ]
[ "${STEPDEF_CAPTURE_INDEXES_LIST[1]}" = "q1" ]
}
6 changes: 3 additions & 3 deletions test/lib/stepdef/pattern.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ teardown() {
run pattern_regex "I run '{command}'"

[ "$status" -eq 0 ]
[ "$output" = "I run (['\"])(.+)\\1" ]
[ "$output" = "I run ('.+'|\".+\")" ]
}

@test "pattern_regex treats single and double quoted token delimiters interchangeably" {
run pattern_regex 'I run "{command}"'

[ "$status" -eq 0 ]
[ "$output" = "I run (['\"])(.+)\\1" ]
[ "$output" = "I run ('.+'|\".+\")" ]
}

@test "pattern_regex turns multiple tokens into capture groups" {
Expand Down Expand Up @@ -78,5 +78,5 @@ teardown() {
run pattern_capture_indexes "I copy {source} to '{destination}'"

[ "$status" -eq 0 ]
[ "$output" = "1 3" ]
[ "$output" = "1 q2" ]
}
Loading