除非指定了 --use-color,否则测试单元会使用控制台而不是 tmux 产生颜色 [英] Test unit results in color using console but not tmux unless --use-color is specified
问题描述
如果我创建一个新的 Rails (3.2.12) 应用程序.将 test-unit
gem 添加到我的开发、测试组和脚手架资源中.当我从 Mac console.app 运行测试时,我得到了颜色输出.
If I create a new Rails (3.2.12) app. Add the test-unit
gem to my development, test group, and then scaffolded resource. When I run the tests from the Mac console.app, I get color output.
bundle exec rake test
当我为应用程序创建 tmux 会话(在 console.app 中)并运行完全相同的命令时.我没有得到颜色输出.但是,如果我通过--use-color"开关,那么我会在 tmux 中获得测试的颜色输出.
When I create a tmux session (in console.app) for the app and run the exact same command. I don't get color output. However if I pass the "--use-color" switch, then I do get color output for the tests in tmux.
bundle exec rake test TESTOPTS="--use-color"
我在 tmux.config
中使用 set -g default-terminal "screen-256color"
设置了 256 种颜色.知道为什么我在没有 TESTOPTS 的情况下运行 rake 任务时在 tmux 中没有颜色吗?
I'm setting 256 colors in my tmux.config
with set -g default-terminal "screen-256color"
. Any idea why I don't get color in tmux when I run the rake task without the TESTOPTS?
推荐答案
看来 test-unit 通过(主要)查看 TERM 环境变量来猜测终端是否支持颜色.不幸的是,screen-256color
不满足 检查它是否进行.
It appears that test-unit guesses whether the terminal supports color by (mainly) looking at the TERM environment variable. Unfortunately, screen-256color
does not satisfy the checks that it makes.
要求将其对 screen
的识别扩展到包括 screen-256color
可能是合理的.
It might be reasonable to ask that its recognition of screen
be extended to include screen-256color
, also.
我认为您可以在配置文件中删除一些条目以提供默认参数.test-unit.yml
(在当前目录中)或 ~/.test-unit.yml
(在你的主目录中的一个隐藏"文件)中的第一个将是加载:
I think you can drop some entries in a configuration file to supply default arguments. The first of test-unit.yml
(in the current directory) or ~/.test-unit.yml
(a "hidden" file in your home directory) will be loaded:
runner: console
console_options:
arguments: --use-color=yes
这篇关于除非指定了 --use-color,否则测试单元会使用控制台而不是 tmux 产生颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!