@@ -1965,7 +1965,6 @@ internal bool IsRunningWithCharacterFileType()
19651965
19661966 [ Theory ]
19671967 [ InlineData ( null , null ) ] // Default: colors enabled
1968- [ InlineData ( "" , null ) ] // NO_COLOR="" (empty string) means colors disabled (variable is set)
19691968 [ InlineData ( "1" , null ) ] // NO_COLOR set, colors disabled
19701969 [ InlineData ( "1" , "1" ) ] // NO_COLOR supersedes FORCE_COLOR
19711970 public void ColorEnvironmentVariables_DisablesColor ( string noColor , string forceColor )
@@ -2011,9 +2010,38 @@ public void ColorEnvironmentVariables_DisablesColor(string noColor, string force
20112010 }
20122011 }
20132012
2013+ #if NET
2014+ // On .NET, empty string environment variables are supported
2015+ [ Theory ]
2016+ [ InlineData ( "" ) ] // NO_COLOR="" (empty string) means colors disabled (variable is set)
2017+ public void ColorEnvironmentVariables_DisablesColor_EmptyString ( string noColor )
2018+ {
2019+ using ( TestEnvironment env = TestEnvironment . Create ( ) )
2020+ {
2021+ env . SetEnvironmentVariable ( "NO_COLOR" , noColor ) ;
2022+
2023+ EventSourceSink es = new EventSourceSink ( ) ;
2024+ SimulatedConsole sc = new SimulatedConsole ( ) ;
2025+ ConsoleLogger logger = new ConsoleLogger ( LoggerVerbosity . Normal , sc . Write , sc . SetColor , sc . ResetColor ) ;
2026+ logger . Initialize ( es ) ;
2027+
2028+ // Log an error
2029+ es . Consume ( new BuildStartedEventArgs ( "Build started" , null ) ) ;
2030+ BuildEventContext context = new BuildEventContext ( 1 , 1 , 1 , 1 ) ;
2031+ BuildErrorEventArgs errorArgs = new BuildErrorEventArgs ( null , "ERR001" , "file.cs" , 1 , 1 , 0 , 0 , "Test error" , null , null ) ;
2032+ errorArgs . BuildEventContext = context ;
2033+ es . Consume ( errorArgs ) ;
2034+
2035+ string log = sc . ToString ( ) ;
2036+ log . ShouldNotContain ( "<red>" ) ;
2037+ log . ShouldNotContain ( "<yellow>" ) ;
2038+ log . ShouldNotContain ( "<green>" ) ;
2039+ }
2040+ }
2041+ #endif
2042+
20142043 [ Theory ]
20152044 [ InlineData ( "1" ) ] // FORCE_COLOR set, colors enabled (will use ANSI codes)
2016- [ InlineData ( "" ) ] // FORCE_COLOR="" (empty string) means colors enabled (variable is set)
20172045 public void ColorEnvironmentVariables_ForcesColor ( string forceColor )
20182046 {
20192047 using ( TestEnvironment env = TestEnvironment . Create ( ) )
@@ -2042,6 +2070,36 @@ public void ColorEnvironmentVariables_ForcesColor(string forceColor)
20422070 }
20432071 }
20442072
2073+ #if NET
2074+ [ Theory ]
2075+ [ InlineData ( "" ) ] // FORCE_COLOR="" (empty string) means colors enabled (variable is set)
2076+ public void ColorEnvironmentVariables_ForcesColor_EmptyString ( string forceColor )
2077+ {
2078+ using ( TestEnvironment env = TestEnvironment . Create ( ) )
2079+ {
2080+ if ( forceColor is not null )
2081+ {
2082+ env . SetEnvironmentVariable ( "FORCE_COLOR" , forceColor ) ;
2083+ }
2084+
2085+ EventSourceSink es = new EventSourceSink ( ) ;
2086+ SimulatedConsole sc = new SimulatedConsole ( ) ;
2087+ ConsoleLogger logger = new ConsoleLogger ( LoggerVerbosity . Normal , sc . Write , sc . SetColor , sc . ResetColor ) ;
2088+ logger . Initialize ( es ) ;
2089+
2090+ // When FORCE_COLOR is set, logger uses ANSI codes which write directly to Console.Out
2091+ es . Consume ( new BuildStartedEventArgs ( "Build started" , null ) ) ;
2092+ BuildEventContext context = new BuildEventContext ( 1 , 1 , 1 , 1 ) ;
2093+ BuildErrorEventArgs errorArgs = new BuildErrorEventArgs ( null , "ERR001" , "file.cs" , 1 , 1 , 0 , 0 , "Test error" , null , null ) ;
2094+ errorArgs . BuildEventContext = context ;
2095+ es . Consume ( errorArgs ) ;
2096+
2097+ // Just verify no crash
2098+ sc . ToString ( ) . ShouldNotBeNull ( ) ;
2099+ }
2100+ }
2101+ #endif
2102+
20452103 [ Theory ]
20462104 [ InlineData ( "false" ) ]
20472105 public void UseColorParameter_DisablesColor ( string paramValue )
0 commit comments