Skip to content

Commit

Permalink
Add test for fusesource#216
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Sep 29, 2023
1 parent 3c6f950 commit 82c26aa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/fusesource/jansi/AnsiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public static void main(String... args) throws IOException {
System.out.println("java.version= " + System.getProperty("java.version") + ", "
+ "java.vendor= " + System.getProperty("java.vendor") + ","
+ " java.home= " + System.getProperty("java.home"));
System.out.println("Console: " + System.console());

System.out.println();

Expand Down
34 changes: 34 additions & 0 deletions src/test/java/org/fusesource/jansi/AnsiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
*/
package org.fusesource.jansi;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;

import org.fusesource.jansi.Ansi.Color;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -181,6 +187,34 @@ public void testColorDisabled() {
}
}

@Test
public void testAnsiMainWithNoConsole() throws Exception {
boolean win = System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win");
Path javaHome = Paths.get(System.getProperty("java.home"));
Path java = javaHome.resolve(win ? "bin\\java.exe" : "bin/java");
String cp = System.getProperty("java.class.path");

Process process = new ProcessBuilder()
.command(java.toString(), "-cp", cp, AnsiMain.class.getName())
.start();

ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (InputStream in = process.getInputStream();
InputStream err = process.getErrorStream(); ) {
byte[] buffer = new byte[8192];
while (true) {
int nb = in.read(buffer);
if (nb > 0) {
baos.write(buffer, 0, nb);
} else {
break;
}
}
}

System.out.println(baos);
}

private static void assertAnsi(String expected, Ansi actual) {
assertEquals(expected.replace("ESC", "\033"), actual.toString());
}
Expand Down

0 comments on commit 82c26aa

Please sign in to comment.