diff options
-rw-r--r-- | src/share/poudriere/include/util.sh | 23 | ||||
-rw-r--r-- | test/Makefile.am | 1 | ||||
-rw-r--r-- | test/Makefile.in | 10 | ||||
-rw-r--r-- | test/stripansi.sh | 35 |
4 files changed, 68 insertions, 1 deletions
diff --git a/src/share/poudriere/include/util.sh b/src/share/poudriere/include/util.sh index 8b039948..10a45d09 100644 --- a/src/share/poudriere/include/util.sh +++ b/src/share/poudriere/include/util.sh @@ -1318,3 +1318,26 @@ globmatch() { return 0 done } + +stripansi() { + [ $# -eq 2 ] || eargs stripansi input output_var + local _input="$1" + local _output_var="$2" + local _gsub + + case "${_input}" in + *\\033*) ;; + *) + setvar "${_output_var}" "${_input}" + return 0 + ;; + esac + + _gsub="${_input}" + _gsub "${_gsub}" '\\033[?m' "" + _gsub "${_gsub}" '\\033[??m' "" + _gsub "${_gsub}" '\\033[?;?m' "" + _gsub "${_gsub}" '\\033[?;??m' "" + + setvar "${_output_var}" "${_gsub}" +} diff --git a/test/Makefile.am b/test/Makefile.am index 5872a6c5..67fdd9e0 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -31,6 +31,7 @@ TESTS=\ relpath.sh \ relpath_common.sh \ shash_basic.sh \ + stripansi.sh \ timespec.sh \ timestamp.sh \ trap_save.sh \ diff --git a/test/Makefile.in b/test/Makefile.in index b7da354f..fc862083 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -464,7 +464,8 @@ TESTS = builtins.sh cache.sh do_clone.sh encode_args.sh getpid.sh \ locked_mkdir_waiters_kill.sh locked_mkdir_waiters_all_lose.sh \ mapfile.sh port_var_fetch.sh prefix_output.sh read_blocking.sh \ read_file.sh relpath.sh relpath_common.sh shash_basic.sh \ - timespec.sh timestamp.sh trap_save.sh $(JAIL_TESTS) prep.sh + stripansi.sh timespec.sh timestamp.sh trap_save.sh \ + $(JAIL_TESTS) prep.sh JAIL_TESTS = \ bulk-bad-DEPENDS_ARGS.sh \ bulk-ignore-listed.sh \ @@ -871,6 +872,13 @@ shash_basic.sh.log: shash_basic.sh --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) +stripansi.sh.log: stripansi.sh + @p='stripansi.sh'; \ + b='stripansi.sh'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) timespec.sh.log: timespec.sh @p='timespec.sh'; \ b='timespec.sh'; \ diff --git a/test/stripansi.sh b/test/stripansi.sh new file mode 100644 index 00000000..ef475e87 --- /dev/null +++ b/test/stripansi.sh @@ -0,0 +1,35 @@ +set -e +. common.sh +. ${SCRIPTPREFIX}/common.sh +. ${SCRIPTPREFIX}/include/colors.pre.sh +set +e + +assert_not "" "${COLOR_BLUE}" "colors are not loaded" + +input="package" +assert_ret 0 stripansi "${input}" stripped +assert "package" "${stripped}" "stripansi output should match" + +input="${COLOR_BLUE}package two" +assert_ret 0 stripansi "${input}" stripped +assert "package two" "${stripped}" "stripansi output should match" + +input="${COLOR_BLUE}package${COLOR_RESET}" +assert_ret 0 stripansi "${input}" stripped +assert "package" "${stripped}" "stripansi output should match" + +input="${COLOR_BLUE}package${COLOR_RESET} " +assert_ret 0 stripansi "${input}" stripped +assert "package " "${stripped}" "stripansi output should match" + +input=" ${COLOR_BLUE}package${COLOR_RESET}" +assert_ret 0 stripansi "${input}" stripped +assert " package" "${stripped}" "stripansi output should match" + +input=" ${COLOR_BLUE}package${COLOR_RESET} " +assert_ret 0 stripansi "${input}" stripped +assert " package " "${stripped}" "stripansi output should match" + +input="${COLOR_BLUE}pa${COLOR_BOLD}${COLOR_WHITE}c${COLOR_RESET}ka${COLOR_BG_CYAN}ge${COLOR_RESET}" +assert_ret 0 stripansi "${input}" stripped +assert "package" "${stripped}" "stripansi output should match" |