mirror of
https://github.com/hneemann/Digital.git
synced 2025-10-03 01:41:16 -04:00
More concise handling of errors occurring during test execution.
This commit is contained in:
parent
70fe4f8d77
commit
e1c65d1f98
@ -9,6 +9,7 @@ import de.neemann.digital.draw.library.ElementNotFoundException;
|
|||||||
import de.neemann.digital.draw.model.ModelCreator;
|
import de.neemann.digital.draw.model.ModelCreator;
|
||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
import de.neemann.digital.testing.*;
|
import de.neemann.digital.testing.*;
|
||||||
|
import de.neemann.gui.ErrorMessage;
|
||||||
import de.neemann.gui.IconCreator;
|
import de.neemann.gui.IconCreator;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@ -47,13 +48,16 @@ public class TestResultDialog extends JDialog {
|
|||||||
Collections.sort(tsl);
|
Collections.sort(tsl);
|
||||||
|
|
||||||
JTabbedPane tp = new JTabbedPane();
|
JTabbedPane tp = new JTabbedPane();
|
||||||
int i=0;
|
int i = 0;
|
||||||
int errorTabIndex=-1;
|
int errorTabIndex = -1;
|
||||||
for (TestSet ts : tsl) {
|
for (TestSet ts : tsl) {
|
||||||
Model model = new ModelCreator(circuit, library).createModel(false);
|
Model model = new ModelCreator(circuit, library).createModel(false);
|
||||||
|
|
||||||
TestResult tr = new TestResult(ts.data).create(model);
|
TestResult tr = new TestResult(ts.data).create(model);
|
||||||
|
|
||||||
|
if (tr.getException() != null)
|
||||||
|
SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorWhileExecutingTests_N0", ts.name)).addCause(tr.getException()).setComponent(this));
|
||||||
|
|
||||||
JTable table = new JTable(new TestResultModel(tr));
|
JTable table = new JTable(new TestResultModel(tr));
|
||||||
table.setDefaultRenderer(MatchedValue.class, new MatchedValueRenderer());
|
table.setDefaultRenderer(MatchedValue.class, new MatchedValueRenderer());
|
||||||
table.setDefaultRenderer(Integer.class, new NumberRenderer());
|
table.setDefaultRenderer(Integer.class, new NumberRenderer());
|
||||||
@ -67,12 +71,12 @@ public class TestResultDialog extends JDialog {
|
|||||||
} else {
|
} else {
|
||||||
tabName = Lang.get("msg_test_N_Failed", ts.name);
|
tabName = Lang.get("msg_test_N_Failed", ts.name);
|
||||||
tabIcon = ICON_FAILED;
|
tabIcon = ICON_FAILED;
|
||||||
errorTabIndex=i;
|
errorTabIndex = i;
|
||||||
}
|
}
|
||||||
tp.addTab(tabName, tabIcon, new JScrollPane(table));
|
tp.addTab(tabName, tabIcon, new JScrollPane(table));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (errorTabIndex>=0)
|
if (errorTabIndex >= 0)
|
||||||
tp.setSelectedIndex(errorTabIndex);
|
tp.setSelectedIndex(errorTabIndex);
|
||||||
|
|
||||||
getContentPane().add(tp);
|
getContentPane().add(tp);
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package de.neemann.digital.gui.components.testing;
|
package de.neemann.digital.gui.components.testing;
|
||||||
|
|
||||||
|
import de.neemann.digital.lang.Lang;
|
||||||
import de.neemann.digital.testing.MatchedValue;
|
import de.neemann.digital.testing.MatchedValue;
|
||||||
import de.neemann.digital.testing.TestResult;
|
import de.neemann.digital.testing.TestResult;
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ public class TestResultModel implements TableModel {
|
|||||||
@Override
|
@Override
|
||||||
public String getColumnName(int columnIndex) {
|
public String getColumnName(int columnIndex) {
|
||||||
if (columnIndex == 0)
|
if (columnIndex == 0)
|
||||||
return "No";
|
return Lang.get("number");
|
||||||
else
|
else
|
||||||
return testResult.getSignalName(columnIndex - 1);
|
return testResult.getSignalName(columnIndex - 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,7 @@ public class TestResult {
|
|||||||
private final ArrayList<Value[]> lines;
|
private final ArrayList<Value[]> lines;
|
||||||
private final ArrayList<Value[]> results;
|
private final ArrayList<Value[]> results;
|
||||||
private boolean allPassed;
|
private boolean allPassed;
|
||||||
|
private Exception exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new testing result
|
* Creates a new testing result
|
||||||
@ -107,7 +108,13 @@ public class TestResult {
|
|||||||
in.value.setBool(!in.value.getBool());
|
in.value.setBool(!in.value.getBool());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
model.doStep();
|
model.doStep();
|
||||||
|
} catch (NodeException | RuntimeException e) {
|
||||||
|
exception = e;
|
||||||
|
allPassed = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
for (TestSignal out : outputs) {
|
for (TestSignal out : outputs) {
|
||||||
MatchedValue matchedValue = new MatchedValue(row[out.index], out.value);
|
MatchedValue matchedValue = new MatchedValue(row[out.index], out.value);
|
||||||
@ -229,7 +236,7 @@ public class TestResult {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T next() {
|
public T next() {
|
||||||
if (value==null)
|
if (value == null)
|
||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
T r = value;
|
T r = value;
|
||||||
value = null;
|
value = null;
|
||||||
@ -275,7 +282,7 @@ public class TestResult {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Value[] next() {
|
public Value[] next() {
|
||||||
if (n>=count)
|
if (n >= count)
|
||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
int mask = 1;
|
int mask = 1;
|
||||||
for (int in : dcIndex) {
|
for (int in : dcIndex) {
|
||||||
@ -287,4 +294,11 @@ public class TestResult {
|
|||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the exception thrown during test test execution, or null if there was no error.
|
||||||
|
*/
|
||||||
|
public Exception getException() {
|
||||||
|
return exception;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,7 @@ public class TestExamples extends TestCase {
|
|||||||
public void testTestExamples() throws Exception {
|
public void testTestExamples() throws Exception {
|
||||||
File examples = new File(Resources.getRoot(), "/dig/test");
|
File examples = new File(Resources.getRoot(), "/dig/test");
|
||||||
assertEquals(42, new FileScanner(this::check).scan(examples));
|
assertEquals(42, new FileScanner(this::check).scan(examples));
|
||||||
assertEquals(33, testCasesInFiles);
|
assertEquals(35, testCasesInFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user