@@ -12,6 +12,15 @@ def self.SGR(*attr) = CSI attr.join(?;), ?m
1212 BOLD = SGR 1
1313 BOLD_UNDERLINE = SGR 1 , 4
1414
15+ setup do
16+ @term_env_vars = ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ]
17+ ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ] = nil , nil , nil
18+ end
19+
20+ teardown do
21+ ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ] = @term_env_vars
22+ end
23+
1524 test "ResponseParseError" do
1625 # The first examples don't add parser state, so this makes no difference.
1726 # It affects the last example, which has parser state.
@@ -64,15 +73,16 @@ def self.SGR(*attr) = CSI attr.join(?;), ?m
6473 "#{ BOLD } #{ msg } (#{ BOLD_UNDERLINE } #{ name } #{ RESET } #{ BOLD } )#{ RESET } " ,
6574 err . detailed_message ( highlight : true , parser_state : false )
6675 )
67- assert_equal ( <<~MSG . strip , err . detailed_message )
76+
77+ expected_no_hl = <<~MSG . strip
6878 #{ msg } (#{ name } )
6979 processed : "tag OK [Error=\\ "Microsoft.Exchange.Error: foo\\ ""
7080 remaining : "] done\\ r\\ n"
7181 pos : 45
7282 lex_state : :EXPR_BEG
7383 token : :QUOTED => "Microsoft.Exchange.Error: foo"
7484 MSG
75- assert_equal ( <<~MSG . strip , err . detailed_message ( highlight : true ) )
85+ expected_no_color = <<~MSG . strip
7686 #{ BOLD } #{ msg } (#{ BOLD_UNDERLINE } #{ name } #{ RESET } #{ BOLD } )#{ RESET }
7787 processed : #{ BOLD } "tag OK [Error=\\ "Microsoft.Exchange.Error: foo\\ ""#{ RESET }
7888 remaining : #{ BOLD_UNDERLINE } "] done\\ r\\ n"#{ RESET }
@@ -81,6 +91,29 @@ def self.SGR(*attr) = CSI attr.join(?;), ?m
8191 token : #{ BOLD } :QUOTED#{ RESET } => #{ BOLD } "Microsoft.Exchange.Error: foo"#{ RESET }
8292 MSG
8393
94+ ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ] = nil , nil , "0"
95+ assert_equal ( expected_no_hl , err . detailed_message )
96+ assert_equal ( expected_no_color , err . detailed_message ( highlight : true ) )
97+
98+ ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ] = "dumb" , "1" , nil
99+ assert_equal ( expected_no_hl , err . detailed_message )
100+ assert_equal ( expected_no_color , err . detailed_message ( highlight : true ) )
101+
102+ ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ] = "xterm" , nil , nil
103+ assert_equal ( expected_no_color , err . detailed_message )
104+ assert_equal ( expected_no_hl , err . detailed_message ( highlight : false ) )
105+
106+ ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ] = "dumb" , nil , "1"
107+ assert_equal ( expected_no_color , err . detailed_message )
108+ assert_equal ( expected_no_hl , err . detailed_message ( highlight : false ) )
109+
110+ ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ] = "unknown" , "1" , "1"
111+ assert_equal ( expected_no_color , err . detailed_message )
112+ assert_equal ( expected_no_hl , err . detailed_message ( highlight : false ) )
113+
114+ # reset to nil
115+ ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ] = nil , nil , nil
116+
84117 # `parser_state` defaults to `Net::IMAP.debug`:
85118 Net ::IMAP . debug = false
86119 assert_equal ( "#{ msg } (#{ name } )" , err . detailed_message )
0 commit comments