Skip to content

Commit

Permalink
Implement quick feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1nksm committed Mar 12, 2020
1 parent 52aee3c commit 419a05b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,5 +1,6 @@
.env
.shellspec-local
.shellspec-quick.log
/*.tar.gz
report
coverage*
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

0 comments on commit 419a05b

Please sign in to comment.