-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(agama): add test cases for agama transpiler (#2722)
* docs: minor doc update #2710 * test: update engine tests #2710 * test: add requirements for test execution in transpiler project #2710 * test: add test cases for transpiler module #2710
- Loading branch information
1 parent
4591e70
commit c68bb3e
Showing
64 changed files
with
692 additions
and
26 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
agama/engine/src/test/java/io/jans/agama/test/InexistentFlowTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.jans.agama.test; | ||
|
||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
public class InexistentFlowTest extends BaseTest { | ||
|
||
@Test | ||
public void test() { | ||
HtmlPage page = launch("flow" + Math.random(), null); | ||
assertFalse(page.getUrl().toString().endsWith(".fls")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
agama/transpiler/src/test/java/io/jans/agama/test/FlowUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.jans.agama.test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.nio.file.Files; | ||
import java.util.AbstractMap.SimpleEntry; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class FlowUtil { | ||
|
||
private static final String EXT = "txt"; | ||
|
||
private static Logger LOG = LogManager.getLogger(FlowUtil.class); | ||
|
||
private FlowUtil() {} | ||
|
||
public static Map<String, String> sourcesOfFolder(String parent) { | ||
|
||
try { | ||
Path path = Paths.get(parent); | ||
LOG.debug("Reading files under {}", path.toAbsolutePath()); | ||
|
||
return Files.walk(path).filter(p -> p.toString().endsWith("." + EXT)) | ||
.map(p -> { | ||
|
||
String code = null; | ||
try { | ||
code = Files.readString(p); | ||
} catch (IOException e) { | ||
LOG.error("Unable to read contents of {}: {}", p, e.getMessage()); | ||
} | ||
return new SimpleEntry(p.toString(), code); | ||
|
||
}).collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString())); | ||
|
||
} catch (IOException e) { | ||
LOG.error(e.getMessage(), e); | ||
return null; | ||
} | ||
|
||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
agama/transpiler/src/test/java/io/jans/agama/test/MalformedFlowsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.jans.agama.test; | ||
|
||
import io.jans.agama.dsl.Transpiler; | ||
import io.jans.agama.dsl.TranspilerException; | ||
import io.jans.agama.dsl.error.SyntaxException; | ||
|
||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.TreeMap; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.fail; | ||
|
||
public class MalformedFlowsTest { | ||
|
||
private Logger logger = LogManager.getLogger(getClass()); | ||
|
||
@Test | ||
public void test() { | ||
|
||
Map<String, String> map = new TreeMap<>(FlowUtil.sourcesOfFolder("target/test-classes/fail")); | ||
//Sonar check likes Map.Entry instead of nicer ways to iterate like map.keySet() | ||
for (Map.Entry<String, String> entry: map.entrySet()) { | ||
String file = entry.getKey(); | ||
|
||
try { | ||
logger.info("Checking syntax of '{}'", file); | ||
Transpiler.runSyntaxCheck(entry.getValue()); | ||
|
||
fail(file + " is expected to have errors but it passed validation"); | ||
} catch(SyntaxException | TranspilerException e) { | ||
String msg = e.getMessage(); | ||
logger.info("{}\n", msg); | ||
} | ||
} | ||
logger.info("{} files examined", map.size()); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
agama/transpiler/src/test/java/io/jans/agama/test/ValidFlowsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.jans.agama.test; | ||
|
||
import io.jans.agama.dsl.Transpiler; | ||
import io.jans.agama.dsl.TranspilerException; | ||
import io.jans.agama.dsl.error.SyntaxException; | ||
|
||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.fail; | ||
|
||
public class ValidFlowsTest { | ||
|
||
private Logger logger = LogManager.getLogger(getClass()); | ||
|
||
@Test | ||
public void test() { | ||
|
||
Map<String, String> map = FlowUtil.sourcesOfFolder("target/test-classes/pass"); | ||
//Sonar check likes Map.Entry instead of nicer ways to iterate like map.keySet() | ||
for (Map.Entry<String, String> entry: map.entrySet()) { | ||
String file = entry.getKey(); | ||
|
||
try { | ||
logger.info("Checking syntax of '{}'", file); | ||
Transpiler.runSyntaxCheck(entry.getValue()); | ||
} catch(SyntaxException | TranspilerException e) { | ||
String msg = e.getMessage(); | ||
logger.error("{}\n", msg); | ||
|
||
fail(file + " has errors", e); | ||
} | ||
} | ||
logger.info("{} files examined", map.size()); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Flow flow | ||
Basepath "" | ||
|
||
x = "\"" | ||
|
||
//Failure reason: string literals cannot contain double quotes inside; last quote is hanging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Flow flow | ||
Basepath "" | ||
|
||
x = .5 | ||
|
||
//Failure reason: a digit is expected before decimal separator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Flow flow | ||
Basepath "" | ||
|
||
x = 'hello' | ||
|
||
//Failure reason: string literals are surrounded by double quotes only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Flow flow | ||
Basepath "" | ||
|
||
x = { "year": 2022, "color": "blue" } | ||
|
||
//Failure reason: map literals are not JSON-like but more like Javascript objects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Flow flow | ||
Basepath "" | ||
|
||
x = [ | ||
1, | ||
2 ] | ||
|
||
//Failure reason: in arrays, only commas can be surrounded by new lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Flow flow | ||
Basepath "" | ||
|
||
x = { for: "you", | ||
function: [ "properly" ], goto: {} | ||
|
||
} | ||
|
||
//Failure reason: in maps, only commas can be surrounded by new lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Flow flow | ||
Basepath "" | ||
|
||
_hey = "you" | ||
|
||
//Failure reason: invalid variable name (underscored prefixed) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Flow flow | ||
Basepath "" | ||
|
||
yO0_ = { weird.Key = false } | ||
|
||
//Failure reason: invalid key name (period character) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Flow flow | ||
Basepath "" | ||
|
||
x = y.oh-me | ||
|
||
//Failure reason: invalid access to key with special character in name (hyphen) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Flow flow | ||
Basepath "" | ||
|
||
x = y["hi"] | ||
|
||
//Failure reason: only a positive number or variable name is allowed for list indexing |
Oops, something went wrong.