Remove utest dependency from tests

This commit is contained in:
2025-10-30 18:43:12 -05:00
parent 5cdd5e3be0
commit 1cb31d719d
7 changed files with 42 additions and 42 deletions

View File

@@ -1,15 +1,15 @@
t() { t() {
haxe -cp hank -lib utest -lib hscript hxml/$1.hxml --interp > test-output.txt haxe -cp hank -lib hscript hxml/$1.hxml --interp > test-output.txt
$VISUAL test-output.txt $VISUAL test-output.txt
} }
ta() { ta() {
haxe -cp hank -lib utest -lib hscript hxml/all-platforms.hxml > test-output.txt haxe -cp hank -lib hscript hxml/all-platforms.hxml > test-output.txt
$VISUAL test-output.txt $VISUAL test-output.txt
} }
tas() { tas() {
haxe -D stop_on_error -cp hank -lib utest -lib hscript hxml/all-platforms.hxml > test-output.txt haxe -D stop_on_error -cp hank -lib hscript hxml/all-platforms.hxml > test-output.txt
$VISUAL test-output.txt $VISUAL test-output.txt
} }

View File

@@ -1,5 +0,0 @@
# @install: lix --silent download "haxelib:/utest#1.13.2" into utest/1.13.2/haxelib
-cp ${HAXE_LIBCACHE}/utest/1.13.2/haxelib/src
-D utest=1.13.2
--macro utest.utils.Macro.checkHaxe()
--macro utest.utils.Macro.importEnvSettings()

View File

@@ -1,65 +1,77 @@
package hank; package hank;
import utest.Assert;
import haxe.ds.Option; import haxe.ds.Option;
import hank.LogUtil; import hank.LogUtil;
using StringTools;
class HankAssert { class HankAssert {
public static function assert(condition: Bool, message: String) {
if (condition) pass(message);
else fail(message);
}
public static function pass(message: String) {
message = ' ' + message;
LogUtil.cleanTrace(message);
}
public static function fail(message: String) {
message = ' ' + message;
LogUtil.cleanTrace(message);
}
/** /**
Assert that two complex values (i.e. algebraic enums) are the same. Assert that two complex values (i.e. algebraic enums) are the same.
**/ **/
public static function equals(expected:Dynamic, actual:Dynamic, ?pos:String) { public static function equals(expected:Dynamic, actual:Dynamic, ?pos:String) {
var verboseMessage = ' Asserting that ${actual} is expected value ${expected}'; var verboseMessage = ' Asserting that ${actual} is expected value ${expected}';
if (Std.string(expected) == Std.string(actual)) { assert(Std.string(expected) == Std.string(actual), verboseMessage);
verboseMessage = ' ' + verboseMessage;
} else {
verboseMessage = ' ' + verboseMessage;
}
LogUtil.cleanTrace(verboseMessage);
var failureMessage = 'Assertion that ${actual} is expected value ${expected} failed ${if (pos!= null) 'at ${pos}' else ''}';
Assert.equals(Std.string(Type.typeof(expected)), Std.string(Type.typeof(actual)), failureMessage);
Assert.equals(Std.string(expected), Std.string(actual), failureMessage);
} }
/** Assert that a string contains an expected substring. **/ /** Assert that a string contains an expected substring. **/
public static function contains(expected:String, actual:String) { public static function contains(expected:String, actual:String) {
Assert.notEquals(-1, actual.indexOf(expected)); var verboseMessage = ' Asserting that "${actual}" contains "${expected}"';
assert(actual.contains(expected), verboseMessage);
} }
/** /**
Assert that a string does not contain an unexpected substring. Assert that a string does not contain an unexpected substring.
**/ **/
public static function notContains(unexpected:String, actual:String) { public static function notContains(unexpected:String, actual:String) {
Assert.equals(-1, actual.indexOf(unexpected)); var verboseMessage = ' Asserting that "${actual}" does not contain "${unexpected}"';
assert(!actual.contains(unexpected), verboseMessage);
} }
public static function isSome<T>(option:Option<T>) { public static function isSome<T>(option:Option<T>) {
var verboseMessage = ' Asserting that ${option} is Some(_)';
switch (option) { switch (option) {
case Some(_): case Some(_):
Assert.equals(0, 0); pass(verboseMessage);
case None: case None:
Assert.fail(); fail(verboseMessage);
} }
} }
public static function isNone<T>(option:Option<T>) { public static function isNone<T>(option:Option<T>) {
var verboseMessage = ' Asserting that ${option} is None';
switch (option) { switch (option) {
case Some(_): case Some(_):
Assert.fail(); fail(verboseMessage);
case None: case None:
Assert.equals(0, 0); pass(verboseMessage);
} }
} }
public static function throws(f:Void->Void, ?message:String) { public static function throws(f:Void->Void, ?message:String) {
try { try {
f(); f();
Assert.fail("Expected an exception to be thrown"); fail("Expected an exception to be thrown");
} catch (e:String) { } catch (e:String) {
if (message != null) { if (message != null) {
Assert.equals(message, e); equals(message, e);
} else {
pass("An exception was thrown, as expected");
} }
Assert.equals(0, 0);
} }
} }
} }

View File

@@ -6,14 +6,12 @@ import hank.Story.StoryFrame;
import hank.LogUtil; import hank.LogUtil;
import hank.HankBuffer; import hank.HankBuffer;
import haxe.CallStack; import haxe.CallStack;
import utest.Assert;
class StoryTestCase extends utest.Test { class StoryTestCase {
var testsDirectory:String; var testsDirectory:String;
var files:PreloadedFiles = new Map(); var files:PreloadedFiles = new Map();
public function new(testsDirectory:String, ?preloadedFiles:PreloadedFiles) { public function new(testsDirectory:String, ?preloadedFiles:PreloadedFiles) {
super();
this.testsDirectory = testsDirectory; this.testsDirectory = testsDirectory;
if (preloadedFiles != null) if (preloadedFiles != null)
this.files = preloadedFiles; this.files = preloadedFiles;
@@ -68,7 +66,7 @@ class StoryTestCase extends utest.Test {
} catch (e:Dynamic) { } catch (e:Dynamic) {
var failMessage = ' Error testing $folder/$file at transcript line $lastTranscriptLine: $e, ${LogUtil.prettifyStack(CallStack.exceptionStack())}'; var failMessage = ' Error testing $folder/$file at transcript line $lastTranscriptLine: $e, ${LogUtil.prettifyStack(CallStack.exceptionStack())}';
LogUtil.cleanTrace(failMessage); LogUtil.cleanTrace(failMessage);
Assert.fail(failMessage); HankAssert.fail(failMessage);
} }
#end #end
} }
@@ -100,7 +98,6 @@ class StoryTestCase extends utest.Test {
} catch (e:Dynamic) { } catch (e:Dynamic) {
LogUtil.cleanTrace(' Error parsing $storyFile: $e'); LogUtil.cleanTrace(' Error parsing $storyFile: $e');
LogUtil.prettyPrintStack(CallStack.exceptionStack()); LogUtil.prettyPrintStack(CallStack.exceptionStack());
Assert.fail();
return; return;
} }
#end #end
@@ -130,7 +127,7 @@ class StoryTestCase extends utest.Test {
} while (line != null && line.startsWith("*")); } while (line != null && line.startsWith("*"));
// Assert that the storyframe is a corresponding HasChoices enum // Assert that the storyframe is a corresponding HasChoices enum
HankAssert.equals(HasChoices(choices), frame); HankAssert.equals(HasChoices(choices, [for(choice in choices) []]), frame);
continue; continue;
} else if (line.startsWith(">")) { } else if (line.startsWith(">")) {

View File

@@ -1,5 +0,0 @@
# @install: lix --silent download "haxelib:/utest#1.13.2" into utest/1.13.2/haxelib
-cp ${HAXE_LIBCACHE}/utest/1.13.2/haxelib/src
-D utest=1.13.2
--macro utest.utils.Macro.checkHaxe()
--macro utest.utils.Macro.importEnvSettings()

2
test.sh Executable file
View File

@@ -0,0 +1,2 @@
source functions.sh
t examples

View File

@@ -1,16 +1,15 @@
package tests.main; package tests.main;
import utest.Test;
import hank.StoryTestCase; import hank.StoryTestCase;
import hank.LogUtil; import hank.LogUtil;
@:build(hank.FileLoadingMacro.build(["examples/"])) @:build(hank.FileLoadingMacro.build(["examples/"]))
class Examples extends Test { class Examples /*extends Test*/ {
public static function main() { public static function main() {
trace('Testing examples for target ${LogUtil.currentTarget()}'); trace('Testing examples for target ${LogUtil.currentTarget()}');
utest.UTest.run([new StoryTestCase("examples" new StoryTestCase("examples"
#if !sys #if !sys
, files , files
#end #end
)]); ).testAllExamples();
} }
} }