Skip to content

Commit

Permalink
Merge ea2010b into ec5377b
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1nksm committed Mar 12, 2020
2 parents ec5377b + ea2010b commit cdfb26c
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/general.sh
Expand Up @@ -541,7 +541,7 @@ shellspec_union_values() {
esac; \
$1=\${3#*\"\$$1\"} && set -- \"\$1\" \"\$2\" \"\$$1\" \"\$4\" && $1=\$2; \
done; \
$1=\$4 && $1=\${$1%\"\$2\"} && $1=\${$1#\"\$2\"}; \
$1=\$4; $1=\${$1%\"\$2\"}; $1=\${$1#\"\$2\"}; $1=\${$1#\"\$2\"}; \
"
eval "$SHELLSPEC_EVAL"
}
Expand Down
30 changes: 29 additions & 1 deletion lib/libexec.sh
Expand Up @@ -132,4 +132,32 @@ signal() {
signal "$@"
}

use puts putsn
read_quickfile() {
eval "{ IFS= read -r $1 || [ \"\$$1\" ]; } &&:" && {
case $# in
2) eval "$2=\${$1%%:*}" ;;
*) eval "$2=\${$1%%:*} $3=\${$1#*:}" ;;
esac
}
}

match_files_pattern() {
SHELLSPEC_EVAL="
shift; \
while [ \$# -lt $(($#*2-2)) ]; do \
$1=\$1; \
escape_pattern $1; \
set -- \"\$@\" \"\$1\"; \
set -- \"\$@\" \"\$1/*\"; \
shift; \
done; \
$1=''; \
while [ \$# -gt 0 ]; do \
$1=\"\${$1}\${$1:+|}\$1\"; \
shift; \
done \
"
eval "$SHELLSPEC_EVAL"
}

use puts putsn escape_pattern
77 changes: 76 additions & 1 deletion lib/libexec/reporter.sh
@@ -1,10 +1,11 @@
#shellcheck shell=sh disable=SC2004

: "${count_specfiles:-} ${count_examples:-}"
: "${count_specfiles:-} ${count_examples:-} ${done:-}"

# shellcheck source=lib/libexec.sh
. "${SHELLSPEC_LIB:-./lib}/libexec.sh"
use import reset_params constants sequence replace each padding trim
use difference_values union_values match_pattern is_empty_file

count() {
count_specfiles=0 count_examples=0
Expand Down Expand Up @@ -112,3 +113,77 @@ read_profiler() {
i=$(($i + 1))
done < "$2" &&:
}

init_quick_data() {
quick_count=0
}

pass_quick_data() {
i=$quick_count
while [ "$i" -gt 0 ]; do
eval "[ \"\${quick_$i:-}\" = \"\$1\" ] &&:" && break
i=$(($i-1))
done
if [ "$i" -eq 0 ]; then
quick_count=$(($quick_count+1)) && i=$quick_count
set -- "$1" "$2" "$3" "quick_$i"
eval "$4=\"\$1\" $4_fail='' $4_pass=''"
else
set -- "$1" "$2" "$3" "quick_$i"
fi
if [ "$3" = "yes" ]; then
eval "$4_pass=\"\$$4_pass\${$4_pass:+:}@\$2\""
else
eval "$4_fail=\"\$$4_fail\${$4_fail:+:}@\$2\""
fi
}

find_quick_data() {
i=1
while [ "$i" -le "$quick_count" ]; do
set -- "$1" "$2" "quick_$i"
eval "set -- \"\$@\" \"\${$3:-}\" \"\${$3_pass:-}\" \"\${$3_fail:-}\""
[ "$2" != "$4" ] && i=$(($i+1)) && continue
"$1" "$4" "$5" "$6"
break
done
}

remove_quick_data() {
i=1
while [ "$i" -le "$quick_count" ]; do
set -- "$1" "quick_$i"
eval "set -- \"\$@\" \"\${$2:-}\""
[ "$1" != "$3" ] && i=$(($i+1)) && continue
unset "$2" "$2_pass" "$2_fail" ||:
break
done
}

list_quick_data() {
i=1
while [ "$i" -le "$quick_count" ]; do
set -- "$1" "quick_$i"
eval "set -- \"\$@\" \"\${$2:-}\" \"\${$2_pass:-}\" \"\${$2_fail:-}\""
[ "$3" ] && "$1" "$3" "$4" "$5"
i=$(($i+1))
done
}

filter_quick_file() {
line='' specfile='' ids='' done="$1" && shift
callback() { if [ "$3" ]; then putsn "$1:$3"; fi; }
while read_quickfile line specfile ids; do
pattern=''
match_files_pattern pattern "$@"
[ "$done" ] && match_pattern "$specfile" "$pattern" && ids=''
filter_ids() {
difference_values ids ":" "$2" # Remove succeeded examples
union_values ids ":" "$3" # Add failed examples
}
find_quick_data filter_ids "$specfile"
remove_quick_data "$specfile"
callback "$specfile" "" "$ids"
done
list_quick_data callback
}
2 changes: 1 addition & 1 deletion lib/libexec/shellspec.sh
Expand Up @@ -2,7 +2,7 @@

# shellcheck source=lib/libexec.sh
. "${SHELLSPEC_LIB:-./lib}/libexec.sh"
use reset_params
use reset_params join match_pattern
load binary

read_options_file() {
Expand Down
26 changes: 25 additions & 1 deletion libexec/shellspec-reporter.sh
Expand Up @@ -23,7 +23,7 @@ exit_status=0 found_focus='' no_examples='' aborted=1 coverage_failed=''
fail_fast='' fail_fast_count=${SHELLSPEC_FAIL_FAST_COUNT:-} reason=''
current_example_index=0 example_index=''
last_example_no='' last_skip_id='' not_enough_examples=''
field_type='' field_tag='' field_example_no='' field_focused=''
field_id='' field_type='' field_tag='' field_example_no='' field_focused=''
field_conditional='' field_skipid='' field_pending='' field_message=''

# shellcheck disable=SC2034
Expand All @@ -32,6 +32,8 @@ succeeded_count='' failed_count='' warned_count='' \
todo_count='' fixed_count='' skipped_count='' suppressed_skipped_count='' \
profiler_count=0 profiler_line=''

[ -e "$SHELLSPEC_QUICK_FILE" ] && init_quick_data

[ "$SHELLSPEC_GENERATORS" ] && mkdir -p "$SHELLSPEC_REPORTDIR"

load_formatter "$SHELLSPEC_FORMATTER" $SHELLSPEC_GENERATORS
Expand Down Expand Up @@ -124,6 +126,13 @@ each_line() {
if [ "$field_tag" = "skipped" ] && [ -z "$example_index" ]; then
inc suppressed_skipped_count
fi
if [ -e "$SHELLSPEC_QUICK_FILE" ]; then
if [ "$field_fail" ] || [ "$field_tag" = "todo" ]; then
pass_quick_data "$field_specfile" "$field_id" no
else
pass_quick_data "$field_specfile" "$field_id" yes
fi
fi
;;
end)
# field_example_count not provided with range or filter
Expand Down Expand Up @@ -190,6 +199,21 @@ else
fi
fi

if [ -e "$SHELLSPEC_QUICK_FILE" ]; then
quick_file="$SHELLSPEC_QUICK_FILE" done=1
[ "${aborted}${interrupt}${not_enough_examples}${fail_fast}" ] && done=''
[ -e "$quick_file" ] && in_quick_file=$quick_file || in_quick_file=/dev/null
quick_file_data=$(filter_quick_file "$done" "$@" < "$in_quick_file")
if [ -s "$quick_file" ] && [ ! "$quick_file_data" ]; then
info "All examples have been passed. Rerun to prevent regression.$LF"
fi
puts "$quick_file_data${quick_file_data:+"$LF"}" > "$quick_file"
fi

if [ ! "$SHELLSPEC_QUICK" ] && is_empty_file "$SHELLSPEC_QUICK_FILE"; then
rm "$SHELLSPEC_QUICK_FILE"
fi

if [ -e "$SHELLSPEC_TMPBASE/$SHELLSPEC_DEPRECATION_LOGFILE" ]; then
deprecated_count=0
while IFS= read -r deprecated; do
Expand Down
22 changes: 22 additions & 0 deletions shellspec
Expand Up @@ -75,6 +75,8 @@ export SHELLSPEC_DEFECT_REDEFINE=''
export SHELLSPEC_DEFECT_SHELL_FLAG=''
export SHELLSPEC_KILL='kill'
export SHELLSPEC_SHEBANG_MULTIARG=''
export SHELLSPEC_QUICK=''
export SHELLSPEC_QUICK_FILE=".shellspec-quick.log"

#shellcheck disable=SC2039
export SHELLSPEC_HOSTNAME=${HOSTNAME:-localhost}
Expand Down Expand Up @@ -156,6 +158,7 @@ Usage: shellspec [options] [files or directories]
[specfiles] randomize the order of specfiles
[examples] randomize the order of examples (slow)
-j, --jobs JOBS Number of parallel jobs to run (0 jobs means disabled)
--[no-]quick Run only non-passed examples the last time they ran [default: disabled]
--[no-]warning-as-failure Treat warning as failure [default: enabled]
--dry-run Print the formatter output without running any examples
--keep-tempdir Do not cleanup temporary directory [default: disabled]
Expand Down Expand Up @@ -272,6 +275,8 @@ parse_options() {
-j | --jobs) [ "${2:-}" ] || invalid 'Require JOBS.'
SHELLSPEC_JOBS=$2
shift ;;
--quick) SHELLSPEC_QUICK=1 ;;
--no-quick) SHELLSPEC_QUICK='' ;;
--dry-run) SHELLSPEC_DRYRUN=1 ;;
--keep-tempdir) SHELLSPEC_KEEP_TEMPDIR=1 ;;
--focus) SHELLSPEC_FOCUS_FILTER=1 ;;
Expand Down Expand Up @@ -454,6 +459,23 @@ case $SHELLSPEC_MODE in (runner | list | translate | syntax-check)
done
esac

if [ "$SHELLSPEC_MODE" = "runner" ] && [ "$SHELLSPEC_QUICK" ]; then
if [ -e "$SHELLSPEC_QUICK_FILE" ]; then
count=$# pattern='' line='' specfile=''
match_files_pattern pattern "$@"
while read_quickfile line specfile; do
! match_pattern "$specfile" "$pattern" || set -- "$@" "$line"
done < "$SHELLSPEC_QUICK_FILE"
if [ "$#" -gt "$count" ] && shift "$count"; then
info "Run only non-passed examples the last time they ran." >&2
fi
else
if ! ( : > "$SHELLSPEC_QUICK_FILE" ) 2>/dev/null; then
warn "Failed to write the quick log for the --quick option."
fi
fi
fi

case $SHELLSPEC_MODE in (runner | list)
if [ "$SHELLSPEC_RANDOM" ] && [ ! "$SHELLSPEC_SEED" ]; then
random_seed SHELLSPEC_SEED "$SHELLSPEC_UNIXTIME" "$$"
Expand Down
36 changes: 28 additions & 8 deletions spec/general_spec.sh
Expand Up @@ -592,18 +592,38 @@ Describe "general.sh"
End

Describe "shellspec_difference_values()"
Before var=@1:@2-1:@1:@2-2:@3
It "removes specified values"
When call shellspec_difference_values var ":" "@5:@1:@2-2:@1"
The variable var should eq "@2-1:@3"
Context 'when values is empty'
Before var=''
It "removes specified values"
When call shellspec_difference_values var ":" "@5:@1:@2-2:@1"
The variable var should eq ""
End
End

Context 'when values is not blank'
Before var=@1:@2-1:@1:@2-2:@3
It "removes specified values"
When call shellspec_difference_values var ":" "@5:@1:@2-2:@1"
The variable var should eq "@2-1:@3"
End
End
End

Describe "shellspec_union_values()"
Before var=@1:@2-1:@1:@2-2:@3
It "removes specified values"
When call shellspec_union_values var ":" "@1:@2-1:@2-3:@3:@4:@3"
The variable var should eq "@1:@2-1:@2-2:@3:@2-3:@4"
Context 'when values is empty'
Before var=''
It "removes specified values"
When call shellspec_union_values var ":" "@1-1:@1-2"
The variable var should eq "@1-1:@1-2"
End
End

Context 'when values is not empty'
Before var=@1:@2-1:@1:@2-2:@3
It "removes specified values"
When call shellspec_union_values var ":" "@1:@2-1:@2-3:@3:@4:@3"
The variable var should eq "@1:@2-1:@2-2:@3:@2-3:@4"
End
End
End

Expand Down

0 comments on commit cdfb26c

Please sign in to comment.