Dramatically prettified test logging
This commit is contained in:
@@ -6,4 +6,10 @@ typedef Choice = {id: Int, onceOnly: Bool, label: Option<String>, condition: Opt
|
||||
|
||||
typedef ChoicePointInfo = {choices: Array<Choice>, fallbackIndex: Int};
|
||||
|
||||
typedef FallbackChoice = {choice: Choice, index: Int};
|
||||
typedef FallbackChoice = {choice: Choice, index: Int};
|
||||
|
||||
class ChoiceExtension {
|
||||
public static function toString(choice: Choice): String {
|
||||
return '*' + Std.string(choice.output.parts[0]) + '...';
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,21 @@ package hank;
|
||||
|
||||
import utest.Assert;
|
||||
import haxe.ds.Option;
|
||||
import hank.LogUtil;
|
||||
|
||||
class HankAssert {
|
||||
/**
|
||||
Assert that two complex values (i.e. algebraic enums) are the same.
|
||||
**/
|
||||
public static function equals(expected: Dynamic, actual: Dynamic, ?pos: String) {
|
||||
var failureMessage = 'Assertion that ${actual} is ${expected} failed ${if (pos!= null) 'at ${pos}' else ''}';
|
||||
var verboseMessage = ' Asserting that ${actual} is expected value ${expected}';
|
||||
if (Std.string(expected) == Std.string(actual)) {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -62,4 +62,11 @@ class LogUtil {
|
||||
return "unknown";
|
||||
|
||||
}
|
||||
|
||||
public static function cleanTrace(msg: Dynamic) {
|
||||
// TODO in Haxe 3.4.7, something is wrong with trace, so this is a workaround to remove position info from clean traces. For now, only on Sys targets
|
||||
#if sys
|
||||
Sys.println(Std.string(msg));
|
||||
#end
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ enum OutputType {
|
||||
ToggleOutput(o: Output, invert: Bool); // Output that will sometimes be displayed (i.e. [bracketed] section in a choice text or the section following the bracketed section)
|
||||
}
|
||||
|
||||
@:allow(tests.ParserTest)
|
||||
@:allow(tests.ParserTest, hank.ChoiceExtension)
|
||||
class Output {
|
||||
var parts: Array<OutputType> = [];
|
||||
var diverted: Bool = false;
|
||||
|
||||
@@ -49,17 +49,17 @@ class StoryTestCase extends utest.Test {
|
||||
|
||||
for (folder in exampleTranscripts.keys()) {
|
||||
if (folder.startsWith('_')) {
|
||||
trace('Skipping tests for example "${folder}"');
|
||||
LogUtil.cleanTrace(' Skipping tests for example "${folder}"');
|
||||
continue;
|
||||
}
|
||||
trace('Running tests for example "${folder}"');
|
||||
LogUtil.cleanTrace(' Running tests for example "${folder}"');
|
||||
|
||||
for (file in exampleTranscripts[folder]) {
|
||||
var disabled = file.indexOf("disabled") != -1;
|
||||
var debug = file.indexOf("debug") != -1;
|
||||
var partial = file.indexOf("partial") != -1;
|
||||
if (!disabled) {
|
||||
trace(' Running ${file}');
|
||||
LogUtil.cleanTrace(' Running ${file}');
|
||||
|
||||
#if stop_on_error
|
||||
validateAgainstTranscript('${testsDirectory}/${folder}/main.hank', '${testsDirectory}/${folder}/${file}', !partial, debug);
|
||||
@@ -67,8 +67,8 @@ class StoryTestCase extends utest.Test {
|
||||
try {
|
||||
validateAgainstTranscript('${testsDirectory}/${folder}/main.hank', '${testsDirectory}/${folder}/${file}', !partial, debug);
|
||||
} catch (e: Dynamic) {
|
||||
var failMessage = 'Error testing $folder/$file at transcript line $lastTranscriptLine: $e, ${LogUtil.prettifyStack(CallStack.exceptionStack()) }';
|
||||
trace(failMessage);
|
||||
var failMessage = ' Error testing $folder/$file at transcript line $lastTranscriptLine: $e, ${LogUtil.prettifyStack(CallStack.exceptionStack()) }';
|
||||
LogUtil.cleanTrace(failMessage);
|
||||
Assert.fail(failMessage);
|
||||
}
|
||||
#end
|
||||
@@ -99,7 +99,7 @@ class StoryTestCase extends utest.Test {
|
||||
try {
|
||||
story = Story.FromFile(storyFile, files, randomSeed);
|
||||
} catch (e: Dynamic) {
|
||||
trace('Error parsing $storyFile: $e');
|
||||
LogUtil.cleanTrace(' Error parsing $storyFile: $e');
|
||||
LogUtil.prettyPrintStack(CallStack.exceptionStack());
|
||||
Assert.fail();
|
||||
return;
|
||||
@@ -143,17 +143,17 @@ class StoryTestCase extends utest.Test {
|
||||
}
|
||||
var index = Std.parseInt(line.substr(0, firstColonIdx))-1;
|
||||
var expectedOutput = line.substr(firstColonIdx+1).trim();
|
||||
// trace('expecting: ${expectedOutput}');
|
||||
|
||||
var output = story.choose(index);
|
||||
// trace('got: ${output}');
|
||||
|
||||
HankAssert.equals(expectedOutput, output);
|
||||
}
|
||||
else if (line.length > 0) {
|
||||
// Assert that the story's next frame is HasText(line)
|
||||
// trace('${line} from ${frame}');
|
||||
//trace('expecting: ${HasText(line)}');
|
||||
//trace('got: $frame');
|
||||
//trace('');
|
||||
|
||||
|
||||
|
||||
|
||||
HankAssert.equals(HasText(line), frame);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user