Skip to content

Commit

Permalink
[MSHARED-1109] MessageUtilsTest fails on unsupported platforms (e.g.,…
Browse files Browse the repository at this point in the history
… Apple Silicon or HP-UX/IA64)

This closes apache#106
  • Loading branch information
kwin authored and michael-o committed Jul 25, 2022
1 parent 5b78029 commit 3f380dd
Showing 1 changed file with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeNoException;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
Expand All @@ -46,12 +47,24 @@ public void testSystem()
{
MessageUtils.systemInstall();
assertThat( System.out, not( sameInstance( currentOut ) ) );
MessageUtils.systemUninstall();
assertThat( System.out, sameInstance( currentOut ) );
}
catch( LinkageError e )
{
assumeNoException( "JAnsi not supported for this platform", e );
}
finally
{
System.setOut( currentOut );
try
{
// uninstall is always necessary due to https://github.com/fusesource/jansi/issues/242
// but might throw exceptions
MessageUtils.systemUninstall();
}
catch ( Throwable t )
{
// ignore any thrown exception like NPE here
}
}
}

Expand All @@ -69,9 +82,28 @@ public int getTerminalWidth()
AnsiOutputStream aos = new AnsiOutputStream( new ByteArrayOutputStream(), width, AnsiMode.Default,
null, AnsiType.Emulation, AnsiColors.Colors256, StandardCharsets.UTF_8,
null, null, false );
AnsiConsole.systemInstall();
AnsiConsole.out = new AnsiPrintStream( aos, true );
assertEquals( 33, MessageUtils.getTerminalWidth() );
AnsiConsole.systemUninstall();
try
{
AnsiConsole.systemInstall();
AnsiConsole.out = new AnsiPrintStream( aos, true );
assertEquals( 33, MessageUtils.getTerminalWidth() );
}
catch( LinkageError e )
{
assumeNoException( "JAnsi not supported for this platform", e );
}
finally
{
try
{
// uninstall is always necessary due to https://github.com/fusesource/jansi/issues/242
// but might throw exceptions
MessageUtils.systemUninstall();
}
catch ( Throwable t )
{
// ignore any thrown exception like NPE here
}
}
}
}

0 comments on commit 3f380dd

Please sign in to comment.