mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 15:26:52 -04:00
adds some text cases
This commit is contained in:
parent
57d66f06ea
commit
77aec94aff
@ -32,7 +32,6 @@ import java.util.ArrayList;
|
|||||||
public class CommandLineTester {
|
public class CommandLineTester {
|
||||||
|
|
||||||
private final CircuitLoader circuitLoader;
|
private final CircuitLoader circuitLoader;
|
||||||
private PrintStream out = System.out;
|
|
||||||
private ArrayList<TestCase> testCases;
|
private ArrayList<TestCase> testCases;
|
||||||
private int testsPassed;
|
private int testsPassed;
|
||||||
|
|
||||||
@ -46,17 +45,6 @@ public class CommandLineTester {
|
|||||||
circuitLoader = new CircuitLoader(file);
|
circuitLoader = new CircuitLoader(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the printer to use
|
|
||||||
*
|
|
||||||
* @param out the {@link PrintStream}
|
|
||||||
* @return this for chained calls
|
|
||||||
*/
|
|
||||||
public CommandLineTester setOutputs(PrintStream out) {
|
|
||||||
this.out = out;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses the test cases from the given file
|
* Uses the test cases from the given file
|
||||||
*
|
*
|
||||||
@ -83,9 +71,10 @@ public class CommandLineTester {
|
|||||||
/**
|
/**
|
||||||
* Executes test test
|
* Executes test test
|
||||||
*
|
*
|
||||||
|
* @param out Stream to output messages
|
||||||
* @return the number of failed test cases
|
* @return the number of failed test cases
|
||||||
*/
|
*/
|
||||||
public int execute() {
|
public int execute(PrintStream out) {
|
||||||
if (testCases == null)
|
if (testCases == null)
|
||||||
testCases = getTestCasesFrom(circuitLoader.getCircuit());
|
testCases = getTestCasesFrom(circuitLoader.getCircuit());
|
||||||
|
|
||||||
@ -168,7 +157,7 @@ public class CommandLineTester {
|
|||||||
CommandLineTester clt = new CommandLineTester(new File(circ.get()));
|
CommandLineTester clt = new CommandLineTester(new File(circ.get()));
|
||||||
if (tests.isSet())
|
if (tests.isSet())
|
||||||
clt.useTestCasesFrom(new File(tests.get()));
|
clt.useTestCasesFrom(new File(tests.get()));
|
||||||
int errors = clt.execute();
|
int errors = clt.execute(System.out);
|
||||||
testsPassed = clt.getTestsPassed();
|
testsPassed = clt.getTestsPassed();
|
||||||
if (errors > 0)
|
if (errors > 0)
|
||||||
throw new CLIException(Lang.get("cli_thereAreTestFailures"), errors).hideHelp();
|
throw new CLIException(Lang.get("cli_thereAreTestFailures"), errors).hideHelp();
|
||||||
|
@ -17,7 +17,7 @@ public class CommandLineTesterTest extends TestCase {
|
|||||||
public void test74181() throws IOException {
|
public void test74181() throws IOException {
|
||||||
File source = new File(Resources.getRoot(), "../../main/dig/lib/DIL Chips/74xx/arithmetic/74181.dig");
|
File source = new File(Resources.getRoot(), "../../main/dig/lib/DIL Chips/74xx/arithmetic/74181.dig");
|
||||||
CommandLineTester tester = new CommandLineTester(source);
|
CommandLineTester tester = new CommandLineTester(source);
|
||||||
int errors = tester.execute();
|
int errors = tester.execute(System.out);
|
||||||
assertEquals(0, errors);
|
assertEquals(0, errors);
|
||||||
assertEquals(32, tester.getTestsPassed());
|
assertEquals(32, tester.getTestsPassed());
|
||||||
}
|
}
|
||||||
@ -25,7 +25,7 @@ public class CommandLineTesterTest extends TestCase {
|
|||||||
public void testFailing() throws IOException {
|
public void testFailing() throws IOException {
|
||||||
File source = new File(Resources.getRoot(), "dig/failingTest.dig");
|
File source = new File(Resources.getRoot(), "dig/failingTest.dig");
|
||||||
CommandLineTester tester = new CommandLineTester(source);
|
CommandLineTester tester = new CommandLineTester(source);
|
||||||
int errors = tester.execute();
|
int errors = tester.execute(System.out);
|
||||||
assertEquals(1, errors);
|
assertEquals(1, errors);
|
||||||
assertEquals(0, tester.getTestsPassed());
|
assertEquals(0, tester.getTestsPassed());
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ public class CommandLineTesterTest extends TestCase {
|
|||||||
CommandLineTester tester = new CommandLineTester(source)
|
CommandLineTester tester = new CommandLineTester(source)
|
||||||
.useTestCasesFrom(new File(Resources.getRoot(), "../../main/dig/sequential/Counter-D.dig"));
|
.useTestCasesFrom(new File(Resources.getRoot(), "../../main/dig/sequential/Counter-D.dig"));
|
||||||
|
|
||||||
int errors = tester.execute();
|
int errors = tester.execute(System.out);
|
||||||
assertEquals(0, errors);
|
assertEquals(0, errors);
|
||||||
assertEquals(1, tester.getTestsPassed());
|
assertEquals(1, tester.getTestsPassed());
|
||||||
}
|
}
|
||||||
@ -48,4 +48,15 @@ public class CommandLineTesterTest extends TestCase {
|
|||||||
assertEquals(1, tc.getTestsPassed());
|
assertEquals(1, tc.getTestsPassed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCommandTestFail() {
|
||||||
|
try {
|
||||||
|
File source = new File(Resources.getRoot(), "dig/failingTest.dig");
|
||||||
|
CommandLineTester.TestCommand tc = new CommandLineTester.TestCommand();
|
||||||
|
tc.execute(new String[]{source.getPath()});
|
||||||
|
fail();
|
||||||
|
} catch (CLIException e) {
|
||||||
|
assertEquals(1, e.getExitCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
34
src/test/java/de/neemann/digital/cli/StatsExportTest.java
Normal file
34
src/test/java/de/neemann/digital/cli/StatsExportTest.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Helmut Neemann.
|
||||||
|
* Use of this source code is governed by the GPL v3 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
package de.neemann.digital.cli;
|
||||||
|
|
||||||
|
import de.neemann.digital.cli.cli.CLIException;
|
||||||
|
import de.neemann.digital.integration.Resources;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
|
public class StatsExportTest extends TestCase {
|
||||||
|
|
||||||
|
public void testStats() throws CLIException {
|
||||||
|
File source = new File(Resources.getRoot(), "../../main/dig/sequential/Counter-T.dig");
|
||||||
|
PrintStream old = System.out;
|
||||||
|
try {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
try (PrintStream out = new PrintStream(baos)) {
|
||||||
|
System.setOut(out);
|
||||||
|
new StatsExport().execute(new String[]{source.getPath()});
|
||||||
|
}
|
||||||
|
String outStr = baos.toString();
|
||||||
|
assertTrue(outStr.contains("FlipflopT,,,,4"));
|
||||||
|
} finally {
|
||||||
|
System.setOut(old);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user