moves the Testdata key to the Keys class

This commit is contained in:
hneemann 2020-11-07 10:19:16 +01:00
parent 989ee5e732
commit ce864cc231
13 changed files with 40 additions and 19 deletions

View File

@ -10,11 +10,11 @@ import de.neemann.digital.cli.cli.BasicCommand;
import de.neemann.digital.cli.cli.CLIException;
import de.neemann.digital.core.ErrorDetector;
import de.neemann.digital.core.Model;
import de.neemann.digital.core.element.Keys;
import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.VisualElement;
import de.neemann.digital.lang.Lang;
import de.neemann.digital.testing.TestCaseDescription;
import de.neemann.digital.testing.TestCaseElement;
import de.neemann.digital.testing.TestExecutor;
import java.io.File;
@ -59,7 +59,7 @@ public class CommandLineTester {
ArrayList<TestCase> tsl = new ArrayList<>();
for (VisualElement el : circuit.getTestCases())
tsl.add(new TestCase(
el.getElementAttributes().get(TestCaseElement.TESTDATA),
el.getElementAttributes().get(Keys.TESTDATA),
el.getElementAttributes().getLabel()));
return tsl;
}

View File

@ -20,6 +20,7 @@ import de.neemann.digital.draw.library.ElementLibrary;
import de.neemann.digital.draw.model.InverterConfig;
import de.neemann.digital.draw.shapes.CustomCircuitShapeType;
import de.neemann.digital.draw.shapes.custom.CustomShapeDescription;
import de.neemann.digital.testing.TestCaseDescription;
import de.neemann.gui.Screen;
import de.neemann.gui.language.Language;
@ -869,4 +870,10 @@ public final class Keys {
public static final Key<Boolean> MIRROR =
new Key<>("mirror", false).allowGroupEdit().setSecondary();
/**
* The test data
*/
public static final Key<TestCaseDescription> TESTDATA =
new Key<>("Testdata", () -> new TestCaseDescription(""));
}

View File

@ -54,7 +54,6 @@ import de.neemann.digital.hdl.printer.CodePrinter;
import de.neemann.digital.hdl.verilog2.VerilogGenerator;
import de.neemann.digital.hdl.vhdl2.VHDLGenerator;
import de.neemann.digital.lang.Lang;
import de.neemann.digital.testing.TestCaseElement;
import de.neemann.digital.testing.TestingDataException;
import de.neemann.digital.toolchain.Configuration;
import de.neemann.digital.undo.ChangedListener;
@ -1131,7 +1130,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
ArrayList<ValueTableDialog.TestSet> tsl = new ArrayList<>();
for (VisualElement el : circuitComponent.getCircuit().getTestCases())
tsl.add(new ValueTableDialog.TestSet(
el.getElementAttributes().get(TestCaseElement.TESTDATA),
el.getElementAttributes().get(Keys.TESTDATA),
el.getElementAttributes().getLabel()));
if (tsl.isEmpty())

View File

@ -5,6 +5,7 @@
*/
package de.neemann.digital.gui.components.testing;
import de.neemann.digital.core.element.Keys;
import de.neemann.digital.draw.elements.PinException;
import de.neemann.digital.draw.elements.VisualElement;
import de.neemann.digital.gui.Main;
@ -14,7 +15,6 @@ import de.neemann.digital.gui.components.modification.ModifyAttribute;
import de.neemann.digital.gui.components.table.ShowStringDialog;
import de.neemann.digital.lang.Lang;
import de.neemann.digital.testing.TestCaseDescription;
import de.neemann.digital.testing.TestCaseElement;
import de.neemann.digital.testing.Transitions;
import de.neemann.digital.testing.parser.ParserException;
import de.neemann.gui.ErrorMessage;
@ -103,7 +103,7 @@ public class TestCaseDescriptionDialog extends JDialog {
data.setDataString(text.getText());
if (parent instanceof Main) {
CircuitComponent cc = ((Main) parent).getCircuitComponent();
element.getElementAttributes().set(TestCaseElement.TESTDATA, data);
element.getElementAttributes().set(Keys.TESTDATA, data);
cc.getMain().startTests();
}
} catch (ParserException | IOException e1) {
@ -122,7 +122,7 @@ public class TestCaseDescriptionDialog extends JDialog {
&& !initialDataString.equals(data.getDataString())
&& parent instanceof Main) {
CircuitComponent cc = ((Main) parent).getCircuitComponent();
cc.modify(new ModifyAttribute<>(element, TestCaseElement.TESTDATA, new TestCaseDescription(data)));
cc.modify(new ModifyAttribute<>(element, Keys.TESTDATA, new TestCaseDescription(data)));
}
dispose();
} catch (ParserException | IOException e1) {

View File

@ -28,7 +28,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import static de.neemann.digital.testing.TestCaseElement.TESTDATA;
import static de.neemann.digital.core.element.Keys.TESTDATA;
import java.util.logging.Level;
import java.util.logging.Logger;

View File

@ -26,7 +26,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import static de.neemann.digital.testing.TestCaseElement.TESTDATA;
import static de.neemann.digital.core.element.Keys.TESTDATA;
/**
* Creates a test bench for a model.

View File

@ -7,6 +7,7 @@ package de.neemann.digital.testing;
import de.neemann.digital.core.Model;
import de.neemann.digital.core.NodeException;
import de.neemann.digital.core.element.Keys;
import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.PinException;
import de.neemann.digital.draw.elements.VisualElement;
@ -188,7 +189,7 @@ public class FolderTestRunner {
ArrayList<TestCase> testCases = new ArrayList<>();
for (VisualElement el : circuit.getTestCases()) {
String label = el.getElementAttributes().getLabel();
TestCaseDescription testData = el.getElementAttributes().get(TestCaseElement.TESTDATA);
TestCaseDescription testData = el.getElementAttributes().get(Keys.TESTDATA);
testCases.add(new TestCase(label, testData));
}
if (testCases.isEmpty()) {

View File

@ -106,4 +106,9 @@ public class TestCaseDescription {
public int hashCode() {
return dataString != null ? dataString.hashCode() : 0;
}
@Override
public String toString() {
return dataString;
}
}

View File

@ -15,18 +15,13 @@ import de.neemann.digital.core.element.*;
*/
public class TestCaseElement implements Element {
/**
* the used {@link ElementAttributes} key
*/
public static final Key<TestCaseDescription> TESTDATA = new Key<>("Testdata", () -> new TestCaseDescription(""));
/**
* The TestCaseElement description
*/
public static final ElementTypeDescription TESTCASEDESCRIPTION
= new ElementTypeDescription("Testcase", TestCaseElement.class)
.addAttribute(Keys.LABEL)
.addAttribute(TESTDATA)
.addAttribute(Keys.TESTDATA)
.addAttribute(Keys.ENABLED)
.supportsHDL();

View File

@ -5,6 +5,7 @@
*/
package de.neemann.digital.draw.library;
import de.neemann.digital.core.element.Keys;
import de.neemann.digital.draw.elements.VisualElement;
import de.neemann.digital.integration.Resources;
import de.neemann.digital.integration.ToBreakRunner;
@ -37,7 +38,7 @@ public class JarComponentManagerTest extends TestCase {
for (VisualElement ve : br.getCircuit().getElements()) {
if (ve.equalsDescription(TestCaseElement.TESTCASEDESCRIPTION)) {
TestCaseDescription td = ve.getElementAttributes().get(TestCaseElement.TESTDATA);
TestCaseDescription td = ve.getElementAttributes().get(Keys.TESTDATA);
TestExecutor tr = new TestExecutor(td).create(br.getModel());
assertTrue(tr.allPassed());
}

View File

@ -375,6 +375,19 @@ public class ParserTest extends TestCase {
assertEquals("false;", c.toString());
}
public void testStringCreation() throws IOException, ParserException, HGSEvalException {
String code = "?>Test:<? print(n); str:=output();";
Statement s = new Parser(code).parse(false);
Context c = new Context().declareVar("n", 3);
s.execute(c);
assertEquals("Test:3", c.getVar("str"));
c = new Context().declareVar("n", 12);
s.execute(c);
assertEquals("Test:12", c.getVar("str"));
}
public void testAddFunction() throws IOException, ParserException, HGSEvalException {
Statement s = new Parser("a : in <?=type(Bits)?>;").parse();
Context funcs = new Context().declareVar("type", new Function(1) {

View File

@ -84,7 +84,7 @@ public class TestExamples extends TestCase {
testCasesInFiles++;
String label = el.getElementAttributes().getLabel();
TestCaseDescription td = el.getElementAttributes().get(TestCaseElement.TESTDATA);
TestCaseDescription td = el.getElementAttributes().get(Keys.TESTDATA);
Model model = new ModelCreator(br.getCircuit(), br.getLibrary()).createModel(false);
ErrorDetector ed = new ErrorDetector();

View File

@ -61,7 +61,7 @@ import java.util.List;
import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
import static de.neemann.digital.draw.shapes.GenericShape.SIZE2;
import static de.neemann.digital.integration.GuiTester.getBaseContainer;
import static de.neemann.digital.testing.TestCaseElement.TESTDATA;
import static de.neemann.digital.core.element.Keys.TESTDATA;
/**
* These tests are excluded from the maven build because gui tests are sometimes fragile.