From efb727bf7b2236f730b972504ed7ec7ccc8c3bcc Mon Sep 17 00:00:00 2001 From: rschoene <rene.schoene@tu-dresden.de> Date: Wed, 6 May 2020 17:43:50 +0200 Subject: [PATCH] Move tests to separate Gradle module. --- build.gradle | 2 - .../jastadd/ros2rag/compiler/Compiler.java | 11 ++- src/test/.gitignore | 3 - src/test/01-input/example/Example.jadd | 47 ------------- src/test/01-input/example/Example.relast | 13 ---- src/test/01-input/example/Example.ros2rag | 29 -------- src/test/01-input/example/linkstate.proto | 38 ----------- src/test/01-input/example/robotconfig.proto | 16 ----- .../jastadd/ros2rag/tests/ExampleTest.java | 58 ---------------- .../jastadd/ros2rag/tests/RosToRagTest.java | 49 ------------- test.build.gradle | 68 ------------------- 11 files changed, 8 insertions(+), 326 deletions(-) delete mode 100644 src/test/.gitignore delete mode 100644 src/test/01-input/example/Example.jadd delete mode 100644 src/test/01-input/example/Example.relast delete mode 100644 src/test/01-input/example/Example.ros2rag delete mode 100644 src/test/01-input/example/linkstate.proto delete mode 100644 src/test/01-input/example/robotconfig.proto delete mode 100644 src/test/java/org/jastadd/ros2rag/tests/ExampleTest.java delete mode 100644 src/test/java/org/jastadd/ros2rag/tests/RosToRagTest.java delete mode 100644 test.build.gradle diff --git a/build.gradle b/build.gradle index 87e174c..9e0bde2 100644 --- a/build.gradle +++ b/build.gradle @@ -157,5 +157,3 @@ jastadd { } generateAst.dependsOn relast - -apply from: 'test.build.gradle' diff --git a/src/main/java/org/jastadd/ros2rag/compiler/Compiler.java b/src/main/java/org/jastadd/ros2rag/compiler/Compiler.java index 9fd90f0..a4f5bdc 100644 --- a/src/main/java/org/jastadd/ros2rag/compiler/Compiler.java +++ b/src/main/java/org/jastadd/ros2rag/compiler/Compiler.java @@ -71,12 +71,17 @@ public class Compiler { printMessage("Writing output files"); // copy MqttUpdater into outputDir + final String mqttUpdaterFileName = "MqttUpdater.jadd"; try { - Files.copy(Paths.get("src", "main", "resources", "MqttUpdater.jadd"), - Paths.get(outputDir, "MqttUpdater.jadd"), + InputStream inputStream = Compiler.class.getClassLoader().getResourceAsStream(mqttUpdaterFileName); + if (inputStream == null) { + throw new CompilerException("Could not open " + mqttUpdaterFileName); + } + Files.copy(inputStream, + Paths.get(outputDir, mqttUpdaterFileName), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { - throw new CompilerException("Could not copy MqttUpdater.java", e); + throw new CompilerException("Could not copy " + mqttUpdaterFileName, e); } writeToFile(outputDir + "/Grammar.relast", ros2Rag.getProgram().generateAbstractGrammar()); writeToFile(outputDir + "/ROS2RAG.jadd", ros2Rag.generateAspect(optionRootNode.getValue())); diff --git a/src/test/.gitignore b/src/test/.gitignore deleted file mode 100644 index e372444..0000000 --- a/src/test/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -02-after-ros2rag/* -03-after-relast/* -java-gen/* diff --git a/src/test/01-input/example/Example.jadd b/src/test/01-input/example/Example.jadd deleted file mode 100644 index 1fd2549..0000000 --- a/src/test/01-input/example/Example.jadd +++ /dev/null @@ -1,47 +0,0 @@ -aspect GrammarTypes { - public class IntPosition { - private final int x, y, z; - - private IntPosition(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public static IntPosition of(int x, int y, int z) { - return new IntPosition(x, y, z); - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public int getZ() { - return z; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - IntPosition that = (IntPosition) o; - return x == that.x && - y == that.y && - z == that.z; - } - - @Override - public int hashCode() { - return java.util.Objects.hash(x, y, z); - } - - @Override - public String toString() { - return "(" + x + ", " + y + ", " + z + ")"; - } - } -} diff --git a/src/test/01-input/example/Example.relast b/src/test/01-input/example/Example.relast deleted file mode 100644 index 5afeb22..0000000 --- a/src/test/01-input/example/Example.relast +++ /dev/null @@ -1,13 +0,0 @@ -Model ::= RobotArm ZoneModel ; - -ZoneModel ::= <Size:IntPosition> SafetyZone:Zone* ; - -Zone ::= Coordinate* ; - -RobotArm ::= Joint* EndEffector <AttributeTestSource:int> /<AppropriateSpeed:double>/ ; // normally this would be: <AttributeTestSource:int> ; - -Joint ::= <Name:String> <CurrentPosition:IntPosition> ; // normally this would be: <CurrentPosition:IntPosition> - -EndEffector : Joint; - -Coordinate ::= <Position:IntPosition> ; diff --git a/src/test/01-input/example/Example.ros2rag b/src/test/01-input/example/Example.ros2rag deleted file mode 100644 index 9168da2..0000000 --- a/src/test/01-input/example/Example.ros2rag +++ /dev/null @@ -1,29 +0,0 @@ -/* Version 2020-04-17 */ -// --- update definitions --- -read Joint.CurrentPosition using ParseLinkState, LinkStateToIntPosition ; -write RobotArm.AppropriateSpeed using CreateSpeedMessage, SerializeRobotConfig ; - -// --- dependency definitions --- -RobotArm.AppropriateSpeed canDependOn Joint.CurrentPosition as dependency1 ; -RobotArm.AppropriateSpeed canDependOn RobotArm.AttributeTestSource as dependency2 ; - -// --- mapping definitions --- -ParseLinkState maps byte[] bytes to panda.Linkstate.PandaLinkState {: - return panda.Linkstate.PandaLinkState.parseFrom(bytes); -:} - -SerializeRobotConfig maps config.Robotconfig.RobotConfig rc to byte[] {: - return rc.toByteArray(); -:} - -LinkStateToIntPosition maps panda.Linkstate.PandaLinkState pls to IntPosition {: - panda.Linkstate.PandaLinkState.Position p = pls.getPos(); - { int i = 0; } - return IntPosition.of((int) p.getPositionX(), (int) p.getPositionY(), (int) p.getPositionZ()); -:} - -CreateSpeedMessage maps double speed to config.Robotconfig.RobotConfig {: - return config.Robotconfig.RobotConfig.newBuilder() - .setSpeed(speed) - .build(); -:} diff --git a/src/test/01-input/example/linkstate.proto b/src/test/01-input/example/linkstate.proto deleted file mode 100644 index dc95138..0000000 --- a/src/test/01-input/example/linkstate.proto +++ /dev/null @@ -1,38 +0,0 @@ -syntax = "proto3"; - -package panda; - -message PandaLinkState { - - string name = 1; - - message Position { - float positionX = 1; - float positionY = 2; - float positionZ = 3; - } - - message Orientation { - float orientationX = 1; - float orientationY = 2; - float orientationZ = 3; - float orientationW = 4; - } - - message TwistLinear { - float twistLinearX = 1; - float twistLinearY = 2; - float twistLinearZ = 3; - } - - message TwistAngular { - float twistAngularX = 1; - float twistAngularY = 2; - float twistAngularZ = 3; - } - - Position pos = 2; - Orientation orient = 3; - TwistLinear tl = 4; - TwistAngular ta = 5; -} diff --git a/src/test/01-input/example/robotconfig.proto b/src/test/01-input/example/robotconfig.proto deleted file mode 100644 index c3e0862..0000000 --- a/src/test/01-input/example/robotconfig.proto +++ /dev/null @@ -1,16 +0,0 @@ -syntax = "proto3"; - -package config; - -message RobotConfig { - - double speed = 1; - bool loopTrajectory = 2; - - enum PlanningMode { - FLUID = 0; - CARTESIAN = 1; - } - - PlanningMode planningMode = 3; -} diff --git a/src/test/java/org/jastadd/ros2rag/tests/ExampleTest.java b/src/test/java/org/jastadd/ros2rag/tests/ExampleTest.java deleted file mode 100644 index 7b41810..0000000 --- a/src/test/java/org/jastadd/ros2rag/tests/ExampleTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.jastadd.ros2rag.tests; - -import example.ast.*; -import org.junit.jupiter.api.Test; - -/** - * Test case "example". - * - * @author rschoene - Initial contribution - */ -public class ExampleTest { - - @Test - public void buildModel() { - Model model = new Model(); - model.MqttSetHost("localhost"); - - ZoneModel zoneModel = new ZoneModel(); - zoneModel.setSize(makePosition(1, 1, 1)); - - IntPosition myPosition = makePosition(0, 0, 0); - Coordinate myCoordinate = new Coordinate(myPosition); - Coordinate leftPosition = new Coordinate(makePosition(-1, 0, 0)); - Coordinate rightPosition = new Coordinate(makePosition(1, 0, 0)); - - Zone safetyZone = new Zone(); - safetyZone.addCoordinate(myCoordinate); - safetyZone.addCoordinate(leftPosition); - safetyZone.addCoordinate(rightPosition); - zoneModel.addSafetyZone(safetyZone); - model.setZoneModel(zoneModel); - - RobotArm robotArm = new RobotArm(); - robotArm.setAttributeTestSource(1); // set initial value, no trigger - - Joint joint1 = new Joint(); - joint1.setName("joint1"); - joint1.setCurrentPosition(myPosition); - - EndEffector endEffector = new EndEffector(); - endEffector.setName("gripper"); - endEffector.setCurrentPosition(makePosition(2, 2, 3)); - - robotArm.addJoint(joint1); - robotArm.setEndEffector(endEffector); - model.setRobotArm(robotArm); - - // add dependencies - robotArm.addDependency1(joint1); - robotArm.addDependency1(endEffector); - robotArm.addDependency2(robotArm); - } - - private static IntPosition makePosition(int x, int y, int z) { - return IntPosition.of(x, y, z); - } - -} diff --git a/src/test/java/org/jastadd/ros2rag/tests/RosToRagTest.java b/src/test/java/org/jastadd/ros2rag/tests/RosToRagTest.java deleted file mode 100644 index adf1933..0000000 --- a/src/test/java/org/jastadd/ros2rag/tests/RosToRagTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.jastadd.ros2rag.tests; - -import org.jastadd.ros2rag.compiler.Compiler; -import org.jastadd.ros2rag.compiler.options.CommandLine; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import java.io.File; -import java.nio.file.Paths; -import java.util.Objects; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -@Disabled("migrating build logic from test to build, this test is disabled for now") -public class RosToRagTest { - - void transform(String inputGrammar, String inputRos2Rag, String rootNode, String outputDir) throws CommandLine.CommandLineException, Compiler.CompilerException { - - System.out.println(Paths.get(".").toAbsolutePath()); - assertTrue(Paths.get(inputGrammar).toFile().exists(), "input grammar does not exist"); - - File outputDirFile = Paths.get(outputDir).toFile(); - if (outputDirFile.exists()) { - assertTrue(outputDirFile.isDirectory()); - if (Objects.requireNonNull(outputDirFile.list(), "Could not read output directory").length != 0) { - System.out.println("output directory is not empty!"); - } - } else { - assertTrue(outputDirFile.mkdir()); - } - - String[] args = { - "--outputDir=" + outputDir, - "--inputGrammar=" + inputGrammar, - "--inputRos2Rag=" + inputRos2Rag, - "--rootNode=" + rootNode - }; - - new Compiler().run(args); - } - - @Test - void transformMinimalExample() throws CommandLine.CommandLineException, Compiler.CompilerException { - transform("src/test/resources/Example.relast", - "src/test/resources/Example.ros2rag", - "Model", - "src/test/resources/out"); - } -} diff --git a/test.build.gradle b/test.build.gradle deleted file mode 100644 index 04252f0..0000000 --- a/test.build.gradle +++ /dev/null @@ -1,68 +0,0 @@ -import org.jastadd.relast.plugin.RelastPlugin -import org.jastadd.relast.plugin.RelastTest -apply plugin: RelastPlugin - -relastTest { - compilerLocation = '../libs/relast.jar' -} - -dependencies { - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.0' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.0' - testImplementation 'org.assertj:assertj-core:3.12.1' - testImplementation group: 'org.fusesource.mqtt-client', name: 'mqtt-client', version: '1.15' - testImplementation group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11' - testImplementation 'com.google.protobuf:protobuf-java:3.0.0' -} - -sourceSets { - test { - java.srcDir "src/test/java-gen" - } -} - -task preprocessExampleTest(type: JavaExec, group: 'verification') { - - doFirst { - delete 'src/test/02-after-ros2rag/example/Grammar.relast', - 'src/test/02-after-ros2rag/example/MqttUpdater.java', - 'src/test/02-after-ros2rag/example/ROS2RAG.jadd' - } - - classpath = sourceSets.main.runtimeClasspath - main = 'org.jastadd.ros2rag.compiler.Compiler' - //noinspection GroovyAssignabilityCheck - args '--outputDir=src/test/02-after-ros2rag/example', - '--inputGrammar=src/test/01-input/example/Example.relast', - '--inputRos2Rag=src/test/01-input/example/Example.ros2rag', - '--rootNode=Model' -} - -//task compileExampleTest(type: JavaExec, group: 'verification') { -// -// doFirst { -// delete 'src/test/java-gen/example' -// } -// -// classpath = sourceSets.main.runtimeClasspath -// main = 'org.jastadd.JastAdd' -// //noinspection GroovyAssignabilityCheck -// args '--o=src/test/java-gen/', '--package=example.ast', -// 'src/test/jastadd-gen/example/Grammar.relast', -// 'src/test/jastadd-gen/example/MqttUpdater.java', -// 'src/test/jastadd-gen/example/ROS2RAG.jadd', -// 'src/test/jastadd/Example.jadd' -//} - -task compileExampleTest(type: RelastTest) { - verbose = true - relastFiles 'src/test/02-after-ros2rag/example/Grammar.relast' - grammarName = 'src/test/03-after-relast/example/example' - packageName = 'example.ast' - moreInputFiles 'src/test/01-input/example/Example.jadd', - 'src/test/02-after-ros2rag/example/MqttUpdater.jadd', - 'src/test/02-after-ros2rag/example/ROS2RAG.jadd' -} - -test.dependsOn compileExampleTest -compileExampleTest.dependsOn preprocessExampleTest -- GitLab