Skip to content

Commit

Permalink
Fix JUnit tests for Console
Browse files Browse the repository at this point in the history
  • Loading branch information
axkr committed Nov 30, 2018
1 parent 7198ac5 commit a6fe966
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,24 @@ public class Console {
private static int COUNTER = 1;

/**
* See: <a href="https://stackoverflow.com/a/20387039/24819">Printing out unicode from Java code issue in windows console</a>
* See: <a href="https://stackoverflow.com/a/20387039/24819">Printing out unicode from Java code issue in windows
* console</a>
*/
private static PrintWriter stdout = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8),
true);
/**
* See: <a href="https://stackoverflow.com/a/20387039/24819">Printing out unicode from Java code issue in windows console</a>
* See: <a href="https://stackoverflow.com/a/20387039/24819">Printing out unicode from Java code issue in windows
* console</a>
*/
private static PrintWriter stderr = new PrintWriter(new OutputStreamWriter(System.err, StandardCharsets.UTF_8),
true);


public static void runConsole(final String args[], PrintWriter out, PrintWriter err) {
stdout = out;
stderr = err;
main(args);
}

public static void main(final String args[]) {
F.initSymbols(null, null, true);
Console console;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,31 @@ public class MMAConsole {
private static int COUNTER = 1;

/**
* See: <a href="https://stackoverflow.com/a/20387039/24819">Printing out unicode from Java code issue in windows console</a>
* See: <a href="https://stackoverflow.com/a/20387039/24819">Printing out unicode from Java code issue in windows
* console</a>
*/
private static PrintWriter stdout = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8),
true);
/**
* See: <a href="https://stackoverflow.com/a/20387039/24819">Printing out unicode from Java code issue in windows console</a>
* See: <a href="https://stackoverflow.com/a/20387039/24819">Printing out unicode from Java code issue in windows
* console</a>
*/
private static PrintWriter stderr = new PrintWriter(new OutputStreamWriter(System.err, StandardCharsets.UTF_8),
true);

static {
// distinguish between lower- and uppercase identifiers
Config.PARSER_USE_LOWERCASE_SYMBOLS = false;
F.initSymbols(null, null, true);

}

public static void runConsole(final String args[], PrintWriter out, PrintWriter err) {
stdout = out;
stderr = err;
main(args);
}

public static void main(final String args[]) {

MMAConsole console;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.matheclipse.core.system;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;

import org.matheclipse.core.eval.Console;

Expand All @@ -16,17 +18,18 @@ public ConsoleTestCase(String name) {
}

private void check(String[] args, String result) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
System.setOut(ps);
StringWriter outWriter = new StringWriter();
// writer for standard outrput
PrintWriter stdout = new PrintWriter(outWriter, true);
// writer for errors
PrintWriter stderr = new PrintWriter(new OutputStreamWriter(System.err, StandardCharsets.UTF_8), true);

Console.main(args);
Console.runConsole(args, stdout, stderr);

System.out.flush();
System.setOut(old);
assertEquals(baos.toString(), //
assertEquals(outWriter.toString(), //
result);
stdout.close();
stderr.close();
}

public void test001() {
Expand Down

0 comments on commit a6fe966

Please sign in to comment.