From 28fee71b718cb6abdbd2537144f369844e7ef94a Mon Sep 17 00:00:00 2001 From: Koichi Nakashima Date: Tue, 10 Nov 2020 21:26:19 +0900 Subject: [PATCH 1/3] Replace --keep-tempdir with --keep-tmpdir --- CHANGELOG.md | 4 ++++ lib/libexec/optparser.sh | 10 +++++++++- libexec/shellspec-runner.sh | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95f3efdc..100aca26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `BeforeEach` / `AfterEach` as synonym for `Before` / `After`. - Added `FORCE_COLOR` environment variable. +### Changed + +- Replace `--keep-tempdir` with `--keep-tmpdir`. + ### Removed - Removed `--kcov-common-options` option. diff --git a/lib/libexec/optparser.sh b/lib/libexec/optparser.sh index cce4bdad..056ceba9 100644 --- a/lib/libexec/optparser.sh +++ b/lib/libexec/optparser.sh @@ -78,8 +78,9 @@ parser_definition() { param LOGFILE --log-file init:='/dev/tty' -- \ 'Log file for %logger directive and trace [default: /dev/tty]' - flag KEEP_TEMPDIR --keep-tempdir -- \ + flag KEEP_TMPDIR --keep-tmpdir -- \ 'Do not cleanup temporary directory [default: disabled]' + flag KEEP_TMPDIR --keep-tempdir validate:'deprecated $1' abbr: hidden:true msg -- '' ' **** Execution ****' '' @@ -410,3 +411,10 @@ error_handler() { "$1" "$2" return 1 } + +deprecated() { + case $1 in + --keep-tempdir) + warn "--keep-tempdir is deprecated. replace with --keep-tmpdir." + esac +} diff --git a/libexec/shellspec-runner.sh b/libexec/shellspec-runner.sh index b839e22f..46773a3c 100755 --- a/libexec/shellspec-runner.sh +++ b/libexec/shellspec-runner.sh @@ -23,7 +23,7 @@ stop_profiler() { cleanup() { "$SHELLSPEC_TRAP" '' INT set -- "$SHELLSPEC_TMPBASE" && SHELLSPEC_TMPBASE='' - [ "$SHELLSPEC_KEEP_TEMPDIR" ] && return 0 + [ "$SHELLSPEC_KEEP_TMPDIR" ] && return 0 [ "$1" ] || return 0 { rmtempdir "$1" & } 2>/dev/null } @@ -118,7 +118,7 @@ SHELLSPEC_INFO="${quick_mode}${info}${info_extra:+ }${info_extra}" mktempdir "$SHELLSPEC_TMPBASE" -if [ "$SHELLSPEC_KEEP_TEMPDIR" ]; then +if [ "$SHELLSPEC_KEEP_TMPDIR" ]; then warn "Keeping temporary directory. " warn "Manually delete: rm -rf \"$SHELLSPEC_TMPBASE\"" fi From 3646c5f795bc01c55a3035cc54ef4acf4250305f Mon Sep 17 00:00:00 2001 From: Koichi Nakashima Date: Tue, 10 Nov 2020 22:10:15 +0900 Subject: [PATCH 2/3] Add --tmpdir option --- lib/core/dsl.sh | 2 +- lib/libexec/optparser.sh | 5 ++++- libexec/shellspec-reporter.sh | 6 +++--- libexec/shellspec-runner.sh | 4 +--- shellspec | 28 ++++++++++++++-------------- spec/core/dsl_spec.sh | 9 +++++++-- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/lib/core/dsl.sh b/lib/core/dsl.sh index 1bf790e1..2184fefc 100644 --- a/lib/core/dsl.sh +++ b/lib/core/dsl.sh @@ -435,7 +435,7 @@ shellspec_logger() { shellspec_deprecated() { set -- "${SHELLSPEC_SPECFILE:-}:${SHELLSPEC_LINENO:-$SHELLSPEC_LINENO_BEGIN}" "$@" - shellspec_putsn "$@" >>"$SHELLSPEC_TMPBASE/$SHELLSPEC_DEPRECATION_LOGFILE" + shellspec_putsn "$@" >>"$SHELLSPEC_DEPRECATION_LOGFILE" } shellspec_intercept() { diff --git a/lib/libexec/optparser.sh b/lib/libexec/optparser.sh index 056ceba9..c5751079 100644 --- a/lib/libexec/optparser.sh +++ b/lib/libexec/optparser.sh @@ -7,7 +7,7 @@ # shellcheck source=lib/getoptions_abbr.sh . "$SHELLSPEC_LIB/getoptions_abbr.sh" -# shellcheck disable=SC1083 +# shellcheck disable=SC1083,SC2016 parser_definition() { extension "$@" set -- "$1" "$2" "error_handler ${3:-echo}" @@ -78,6 +78,9 @@ parser_definition() { param LOGFILE --log-file init:='/dev/tty' -- \ 'Log file for %logger directive and trace [default: /dev/tty]' + param TMPDIR --tmpdir init:="${TMPDIR:-${TMP:-/tmp}}" -- \ + 'Specify temporary directory [default: $TMPDIR, $TMP or /tmp]' + flag KEEP_TMPDIR --keep-tmpdir -- \ 'Do not cleanup temporary directory [default: disabled]' flag KEEP_TMPDIR --keep-tempdir validate:'deprecated $1' abbr: hidden:true diff --git a/libexec/shellspec-reporter.sh b/libexec/shellspec-reporter.sh index 175ed5e7..847ad726 100755 --- a/libexec/shellspec-reporter.sh +++ b/libexec/shellspec-reporter.sh @@ -7,7 +7,7 @@ interrupt='' "$SHELLSPEC_TRAP" 'interrupt=1' INT "$SHELLSPEC_TRAP" '' TERM -echo $$ > "$SHELLSPEC_TMPBASE/$SHELLSPEC_REPORTER_PID" +echo $$ > "$SHELLSPEC_REPORTER_PID" # shellcheck source=lib/libexec/reporter.sh . "${SHELLSPEC_LIB:-./lib}/libexec/reporter.sh" @@ -178,11 +178,11 @@ if [ -e "$SHELLSPEC_QUICK_FILE" ] && [ ! "$interrupt" ]; then puts "$quick_file_data${quick_file_data:+"$LF"}" | sort > "$quick_file" fi -if [ -e "$SHELLSPEC_TMPBASE/$SHELLSPEC_DEPRECATION_LOGFILE" ]; then +if [ -e "$SHELLSPEC_DEPRECATION_LOGFILE" ]; then count=0 found='Found ' while IFS= read -r line && inc count; do [ "$SHELLSPEC_DEPRECATION_LOG" ] && info "$line" - done < "$SHELLSPEC_TMPBASE/$SHELLSPEC_DEPRECATION_LOGFILE" + done < "$SHELLSPEC_DEPRECATION_LOGFILE" pluralize found "$count deprecation" if [ "$SHELLSPEC_DEPRECATION_LOG" ]; then info "$found. Use --hide-deprecations to hide the details." diff --git a/libexec/shellspec-runner.sh b/libexec/shellspec-runner.sh index 46773a3c..ae0e31b4 100755 --- a/libexec/shellspec-runner.sh +++ b/libexec/shellspec-runner.sh @@ -3,8 +3,6 @@ set -eu -export SHELLSPEC_PROFILER_SIGNAL="$SHELLSPEC_TMPBASE/profiler.signal" - # shellcheck source=lib/libexec/runner.sh . "${SHELLSPEC_LIB:-./lib}/libexec/runner.sh" @@ -32,7 +30,7 @@ interrupt() { "$SHELLSPEC_TRAP" '' TERM # Workaround for posh: Prevent display 'Terminated'. stop_profiler reporter_pid='' - read_pid_file reporter_pid "$SHELLSPEC_TMPBASE/$SHELLSPEC_REPORTER_PID" 0 + read_pid_file reporter_pid "$SHELLSPEC_REPORTER_PID" 0 [ "$reporter_pid" ] && sleep_wait signal 0 "$reporter_pid" 2>/dev/null signal TERM 0 2>/dev/null &&: cleanup diff --git a/shellspec b/shellspec index 0e64a659..3b584714 100755 --- a/shellspec +++ b/shellspec @@ -35,28 +35,19 @@ export SHELLSPEC_BUILTIN_PRINTF='' export SHELLSPEC_BUILTIN_PRINT='' export SHELLSPEC_BUILTIN_TYPESETF='' export SHELLSPEC_TIME='' -export SHELLSPEC_TMPBASE='' -export SHELLSPEC_TIME_LOG='' export SHELLSPEC_REPORTDIR='' export SHELLSPEC_BANNER_FILE='' export SHELLSPEC_LIST='' export SHELLSPEC_COUNT_FILE='' export SHELLSPEC_UNIXTIME='' export SHELLSPEC_DEBUG_TRAP='' -export SHELLSPEC_TMPDIR=${TMPDIR:-${TMP:-/tmp}} -export SHELLSPEC_DEPRECATION_LOGFILE=".shellspec-deprecation.log" export SHELLSPEC_INFILE=file export SHELLSPEC_COVERAGE_SETUP='' export SHELLSPEC_COVERAGE_SHELL_OPTIONS='' export SHELLSPEC_COVERAGE_DIR='' -export SHELLSPEC_KCOV_COMMON_OPTS='' # TODO: remove export SHELLSPEC_KCOV_COMPATIBLE_SHELL='' export SHELLSPEC_KCOV_VERSION='' -export SHELLSPEC_KCOV_FILENAME='' -export SHELLSPEC_KCOV_IN_FILE='' export SHELLSPEC_OUTPUT_FD=9 -export SHELLSPEC_REPORTER_PID='.shellspec-reporter.pid' -export SHELLSPEC_PROFILER_LOG='' export SHELLSPEC_PROFILER_REPORT=".shellspec-profiler.log" export SHELLSPEC_DEFECT_READONLY='' export SHELLSPEC_DEFECT_BUILTIN='' @@ -138,13 +129,11 @@ SHELLSPEC_SPECDIR="$SHELLSPEC_PROJECT_ROOT/spec" SHELLSPEC_REPORTDIR="$SHELLSPEC_PROJECT_ROOT/report" SHELLSPEC_COVERAGE_DIR="$SHELLSPEC_PROJECT_ROOT/coverage" SHELLSPEC_LOAD_PATH="$SHELLSPEC_SPECDIR:$SHELLSPEC_LIB:$SHELLSPEC_REPORTERLIB" -SHELLSPEC_TMPBASE="${SHELLSPEC_TMPDIR%/}/shellspec.$SHELLSPEC_UNIXTIME.$$" SHELLSPEC_SUPPORT_BIN="$SHELLSPEC_LIB/support-bin.sh" SHELLSPEC_SUPPORT_BINDIR="$SHELLSPEC_SPECDIR/support/bin" -SHELLSPEC_TIME_LOG="$SHELLSPEC_TMPBASE/.shellspec-time.log" -SHELLSPEC_PROFILER_LOG="$SHELLSPEC_TMPBASE/.shellspec-profiler.log" SHELLSPEC_BANNER_FILE="$SHELLSPEC_SPECDIR/banner" +export SHELLSPEC_KCOV_COMMON_OPTS='' while IFS= read -r option; do SHELLSPEC_KCOV_COMMON_OPTS="$SHELLSPEC_KCOV_COMMON_OPTS$option " done </dev/null; then diff --git a/spec/core/dsl_spec.sh b/spec/core/dsl_spec.sh index 4dfb62de..a9469949 100644 --- a/spec/core/dsl_spec.sh +++ b/spec/core/dsl_spec.sh @@ -1053,10 +1053,15 @@ Describe "core/dsl.sh" End Describe "shellspec_deprecated()" + # shellcheck disable=SC2034 + setup() { + SHELLSPEC_SPECFILE=spec.sh + SHELLSPEC_LINENO=10 + SHELLSPEC_DEPRECATION_LOGFILE="$SHELLSPEC_TMPBASE/test-deprecation.log" + } It 'outputs to logfile' Path log="$SHELLSPEC_TMPBASE/test-deprecation.log" - BeforeRun SHELLSPEC_SPECFILE=spec.sh SHELLSPEC_LINENO=10 - BeforeRun SHELLSPEC_DEPRECATION_LOGFILE=test-deprecation.log + BeforeRun "setup" When run shellspec_deprecated "deprecated test" The contents of file log should eq "spec.sh:10 deprecated test" End From d75e858abc92308e1fbac8ae0e1b21c2b3202bbd Mon Sep 17 00:00:00 2001 From: Koichi Nakashima Date: Tue, 10 Nov 2020 22:20:38 +0900 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 100aca26..567d7f5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,10 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `BeforeEach` / `AfterEach` as synonym for `Before` / `After`. - Added `FORCE_COLOR` environment variable. +- Added `--tmpdir` option. ### Changed -- Replace `--keep-tempdir` with `--keep-tmpdir`. +- Replaced `--keep-tempdir` with `--keep-tmpdir`. ### Removed