module ParallelTests::Tasks
def suppress_output(command, ignore_regex)
- defining a new rake task like silence_schema would force users to load parallel_tests in test env
- pipefail is not supported in (zsh)
- pipefail makes pipe fail with exitstatus of first failed command
- sed changes 1 exitstatus to 0
- grep changes 0 exitstatus to 1 if nothing matches
- sed does not support | without -r
normally I'd not do this, but it has been lots of fun and a great learning experience :)
removing certain lines from the output without changing the exit-status
this is a crazy-complex solution for a very simple problem:
def suppress_output(command, ignore_regex) activate_pipefail = "set -o pipefail" remove_ignored_lines = %{(grep -v #{Shellwords.escape(ignore_regex)} || true)} # remove nil values (ex: #purge_before_load returns nil) command.compact! if system('/bin/bash', '-c', "#{activate_pipefail} 2>/dev/null") shell_command = "#{activate_pipefail} && (#{Shellwords.shelljoin(command)}) | #{remove_ignored_lines}" ['/bin/bash', '-c', shell_command] else command end end