From d6e8d39762a2c0b552d9be9d62eaa977f56f4619 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 15 May 2019 10:26:05 -0600 Subject: [PATCH] Refactoring the testing system Close #58 Close #40 --- .gitignore | 3 ++- .travis.yml | 4 ++-- README.md | 5 +++++ all-tests.hxml | 4 ---- examples-debug.hxml | 5 ----- examples-test.hxml | 4 ---- functions.sh | 12 ++++++++++++ hank/FileLoadingMacro.hx | 15 ++++++++++----- hank/HankBuffer.hx | 4 +++- hxml/all-platforms.hxml | 12 ++++++++++++ hxml/all.hxml | 7 +++++++ hxml/examples.hxml | 1 + hxml/internals.hxml | 1 + internals-test.hxml | 4 ---- js/index.html | 5 +++++ tests/AllTestsMain.hx | 9 --------- tests/HInterfaceTest.hx | 3 ++- tests/HankBufferTest.hx | 9 +++++---- tests/{ExamplesTestMain.hx => main/Examples.hx} | 4 ++-- tests/{InternalsTestMain.hx => main/Internals.hx} | 4 ++-- 20 files changed, 71 insertions(+), 44 deletions(-) delete mode 100644 all-tests.hxml delete mode 100644 examples-debug.hxml delete mode 100644 examples-test.hxml create mode 100644 functions.sh create mode 100644 hxml/all-platforms.hxml create mode 100644 hxml/all.hxml create mode 100644 hxml/examples.hxml create mode 100644 hxml/internals.hxml delete mode 100644 internals-test.hxml create mode 100644 js/index.html delete mode 100644 tests/AllTestsMain.hx rename tests/{ExamplesTestMain.hx => main/Examples.hx} (81%) rename tests/{InternalsTestMain.hx => main/Internals.hx} (80%) diff --git a/.gitignore b/.gitignore index 5cbfd86..5bff5e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ examples/shave/ examples/petIntersection/ transcript.hlog -validating.hlog \ No newline at end of file +validating.hlog +js/hank.js diff --git a/.travis.yml b/.travis.yml index 3fc31cc..86ae918 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: haxe haxe: - - "4.0.0-preview.5" + - "3.4.7" hxml: - - test.hxml \ No newline at end of file + - hxml/all-platforms.hxml diff --git a/README.md b/README.md index 34f06b6..d2dd3da 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,11 @@ Portable narrative scripting language based on Ink. Hank is a more portable answer to Inkle's open-source [Ink](http://github.com/inkle/ink) engine. It is currently just a proof of concept, but you may use it at your own risk. +Supported targets: + +* JavaScript +* C++ + ## Comparison with Ink and Inkjs |Feature|Ink|Inkjs|Hank| diff --git a/all-tests.hxml b/all-tests.hxml deleted file mode 100644 index 7a2be1b..0000000 --- a/all-tests.hxml +++ /dev/null @@ -1,4 +0,0 @@ --lib hscript --lib utest --main tests.AllTestsMain ---interp diff --git a/examples-debug.hxml b/examples-debug.hxml deleted file mode 100644 index 1afe4a7..0000000 --- a/examples-debug.hxml +++ /dev/null @@ -1,5 +0,0 @@ --lib hscript --lib utest --debug --main tests.ExamplesTestMain --js index.js diff --git a/examples-test.hxml b/examples-test.hxml deleted file mode 100644 index 803ec3d..0000000 --- a/examples-test.hxml +++ /dev/null @@ -1,4 +0,0 @@ --lib hscript --lib utest --main tests.ExamplesTestMain ---interp diff --git a/functions.sh b/functions.sh new file mode 100644 index 0000000..a1ba467 --- /dev/null +++ b/functions.sh @@ -0,0 +1,12 @@ +t() { + haxe hxml/$1.hxml --interp +} + +ta() { + haxe hxml/all-platforms.hxml +} + +debug() { + haxe -js js/hank.js hxml/all.hxml + chromium-browser js/index.html +} \ No newline at end of file diff --git a/hank/FileLoadingMacro.hx b/hank/FileLoadingMacro.hx index b33cbbc..cff31df 100644 --- a/hank/FileLoadingMacro.hx +++ b/hank/FileLoadingMacro.hx @@ -16,7 +16,12 @@ class FileLoadingMacro { if (file.endsWith("/")) { files.remove(file); - files = files.concat(recursiveLoop(file)); + var dirFiles = recursiveLoop(file); + if (dirFiles.length == 0) { + throw 'No files found in directory "$file"'; + } + + files = files.concat(dirFiles); } else { ++i; } @@ -51,21 +56,21 @@ class FileLoadingMacro { static function recursiveLoop(directory:String, ?files: Array): Array { if (files == null) files = []; if (sys.FileSystem.exists(directory)) { - trace("directory found: " + directory); + //trace("directory found: " + directory); for (file in sys.FileSystem.readDirectory(directory)) { var path = haxe.io.Path.join([directory, file]); if (!sys.FileSystem.isDirectory(path)) { - trace("file found: " + path); + //trace("file found: " + path); // do something with file files.push(path.toString()); } else { var directory = haxe.io.Path.addTrailingSlash(path); - trace("directory found: " + directory); + //trace("directory found: " + directory); files = recursiveLoop(directory, files); } } } else { - trace('"$directory" does not exists'); + //trace('"$directory" does not exists'); } return files; diff --git a/hank/HankBuffer.hx b/hank/HankBuffer.hx index 58c9157..0f139b3 100644 --- a/hank/HankBuffer.hx +++ b/hank/HankBuffer.hx @@ -90,7 +90,9 @@ class HankBuffer { #if sys var rawBuffer = sys.io.File.getContent(path); #else - if (files == null || !files.exists(path)) { + if (files == null) { + throw 'Tried to open file $path on a non-sys platform without passing in preloaded files'; + } else if (!files.exists(path)) { throw 'Tried to open file $path that was not pre-loaded'; } var rawBuffer = files[path]; diff --git a/hxml/all-platforms.hxml b/hxml/all-platforms.hxml new file mode 100644 index 0000000..a3966e7 --- /dev/null +++ b/hxml/all-platforms.hxml @@ -0,0 +1,12 @@ +-js out.js +-cmd node out.js +hxml/all.hxml +--next + +--interp +hxml/all.hxml +--next + +-cpp +hxml/all.hxml +--next \ No newline at end of file diff --git a/hxml/all.hxml b/hxml/all.hxml new file mode 100644 index 0000000..c7d5c67 --- /dev/null +++ b/hxml/all.hxml @@ -0,0 +1,7 @@ +-cp hank +-lib hscript +-lib utest +--each +hxml/examples.hxml +--next +hxml/internals.hxml \ No newline at end of file diff --git a/hxml/examples.hxml b/hxml/examples.hxml new file mode 100644 index 0000000..6f5e882 --- /dev/null +++ b/hxml/examples.hxml @@ -0,0 +1 @@ +-main tests.main.Examples \ No newline at end of file diff --git a/hxml/internals.hxml b/hxml/internals.hxml new file mode 100644 index 0000000..2a50bd0 --- /dev/null +++ b/hxml/internals.hxml @@ -0,0 +1 @@ +-main tests.main.Internals \ No newline at end of file diff --git a/internals-test.hxml b/internals-test.hxml deleted file mode 100644 index 65daaed..0000000 --- a/internals-test.hxml +++ /dev/null @@ -1,4 +0,0 @@ --lib hscript --lib utest --main tests.InternalsTestMain ---interp diff --git a/js/index.html b/js/index.html new file mode 100644 index 0000000..ba2092a --- /dev/null +++ b/js/index.html @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/tests/AllTestsMain.hx b/tests/AllTestsMain.hx deleted file mode 100644 index 47752ba..0000000 --- a/tests/AllTestsMain.hx +++ /dev/null @@ -1,9 +0,0 @@ -package tests; -import utest.Test; - -class AllTestsMain extends Test { - public static function main() { - InternalsTestMain.main(); - ExamplesTestMain.main(); - } -} \ No newline at end of file diff --git a/tests/HInterfaceTest.hx b/tests/HInterfaceTest.hx index d937bc4..1811e03 100644 --- a/tests/HInterfaceTest.hx +++ b/tests/HInterfaceTest.hx @@ -19,6 +19,7 @@ class TestObject { } +@:build(hank.FileLoadingMacro.build(["examples/diverts/"])) class HInterfaceTest extends utest.Test { var hInterface: HInterface; @@ -26,7 +27,7 @@ class HInterfaceTest extends utest.Test { var root: Array; public function setup() { - storyTree = StoryNode.FromAST(new Parser().parseFile("examples/diverts/main.hank")); + storyTree = StoryNode.FromAST(new Parser().parseFile("examples/diverts/main.hank", files)); var viewCounts = storyTree.createViewCounts(); root = [storyTree]; diff --git a/tests/HankBufferTest.hx b/tests/HankBufferTest.hx index a7f93cc..83f555b 100644 --- a/tests/HankBufferTest.hx +++ b/tests/HankBufferTest.hx @@ -7,6 +7,7 @@ import hank.HankBuffer; import hank.HankBuffer.Position; import hank.HankAssert; +@:build(hank.FileLoadingMacro.build(["examples/parsing/"])) class HankBufferTest extends utest.Test { var file: HankBuffer; var path: String; @@ -14,7 +15,7 @@ class HankBufferTest extends utest.Test { function setup() { path = 'examples/parsing/file.txt'; - file = HankBuffer.FromFile(path); + file = HankBuffer.FromFile(path, files); expectedPosition = new Position(path, 1, 1); } @@ -103,7 +104,7 @@ class HankBufferTest extends utest.Test { } function testGetLineTrimming() { - file = HankBuffer.FromFile('examples/parsing/whitespace.txt'); + file = HankBuffer.FromFile('examples/parsing/whitespace.txt', files); HankAssert.equals(Some("Just give me this output."), file.peekLine("lr")); HankAssert.equals(Some(" Just give me this output."), file.peekLine("r")); @@ -116,14 +117,14 @@ class HankBufferTest extends utest.Test { } function testSkipWhitespace() { - file = HankBuffer.FromFile('examples/parsing/whitespace.txt'); + file = HankBuffer.FromFile('examples/parsing/whitespace.txt', files); file.skipWhitespace(); HankAssert.equals("Just", file.take(4)); } function testFindNestedExpression() { - file = HankBuffer.FromFile('examples/parsing/nesting.txt'); + file = HankBuffer.FromFile('examples/parsing/nesting.txt', files); var slice1 = file.findNestedExpression('{', '}', 0); HankAssert.contains("doesn't contain what comes first", slice1.unwrap().checkValue()); HankAssert.contains("Ends before here", slice1.unwrap().checkValue()); diff --git a/tests/ExamplesTestMain.hx b/tests/main/Examples.hx similarity index 81% rename from tests/ExamplesTestMain.hx rename to tests/main/Examples.hx index e28eb00..416a731 100644 --- a/tests/ExamplesTestMain.hx +++ b/tests/main/Examples.hx @@ -1,9 +1,9 @@ -package tests; +package tests.main; import utest.Test; import hank.StoryTestCase; @:build(hank.FileLoadingMacro.build(["examples/"])) -class ExamplesTestMain extends Test { +class Examples extends Test { public static function main() { utest.UTest.run([new StoryTestCase("examples" #if !sys diff --git a/tests/InternalsTestMain.hx b/tests/main/Internals.hx similarity index 80% rename from tests/InternalsTestMain.hx rename to tests/main/Internals.hx index 4796400..ae5fa72 100644 --- a/tests/InternalsTestMain.hx +++ b/tests/main/Internals.hx @@ -1,8 +1,8 @@ -package tests; +package tests.main; import utest.Test; import hank.StoryTestCase; -class InternalsTestMain extends Test { +class Internals extends Test { public static function main() { utest.UTest.run([new HInterfaceTest(), new HankBufferTest(), new ParserTest(), new StoryTreeTest(), new FileLoadingMacroTest()]); }