|
@@ -1,14 +1,13 @@
|
|
|
-import HaxeServer;
|
|
|
+import haxe.display.JsonModuleTypes.JsonModuleType;
|
|
|
import haxe.Json;
|
|
|
+import HaxeServer;
|
|
|
import utest.Assert;
|
|
|
using StringTools;
|
|
|
-
|
|
|
-typedef Message<T> = {
|
|
|
- kind: String,
|
|
|
- data: T
|
|
|
-}
|
|
|
+using Lambda;
|
|
|
|
|
|
class TestContext {
|
|
|
+ public var messages:Array<String> = []; // encapsulation is overrated
|
|
|
+
|
|
|
public var displayServerConfig:DisplayServerConfigBase;
|
|
|
|
|
|
public function new(config:DisplayServerConfigBase) {
|
|
@@ -17,7 +16,12 @@ class TestContext {
|
|
|
|
|
|
public function sendErrorMessage(msg:String) { }
|
|
|
|
|
|
- public function sendLogMessage(msg:String) { }
|
|
|
+ public function sendLogMessage(msg:String) {
|
|
|
+ var split = msg.split("\n");
|
|
|
+ for (message in split) {
|
|
|
+ messages.push(message.trim());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class HaxeServerTestCase {
|
|
@@ -25,7 +29,7 @@ class HaxeServerTestCase {
|
|
|
var server:HaxeServer;
|
|
|
var vfs:Vfs;
|
|
|
var testDir:String;
|
|
|
- var messages:Array<Message<Any>>;
|
|
|
+ var storedTypes:Array<JsonModuleType<Any>>;
|
|
|
|
|
|
public function new() {
|
|
|
testDir = "test/cases/" + Type.getClassName(Type.getClass(this));
|
|
@@ -46,13 +50,16 @@ class HaxeServerTestCase {
|
|
|
server.stop();
|
|
|
}
|
|
|
|
|
|
- function haxe(args:Array<String>, done:Void -> Void) {
|
|
|
- args = args.concat(["-D", "compilation-server-test"]);
|
|
|
+ function runHaxe(args:Array<String>, storeTypes = false, done:Void -> Void) {
|
|
|
+ context.messages = [];
|
|
|
+ storedTypes = [];
|
|
|
+ if (storeTypes) {
|
|
|
+ args = args.concat(['--display', '{ "method": "typer/compiledTypes", "id": 1 }']);
|
|
|
+ }
|
|
|
server.process(args, null, function(result) {
|
|
|
- if (result == "") {
|
|
|
- result = "{}";
|
|
|
+ if (storeTypes) {
|
|
|
+ storedTypes = Json.parse(result).result.result;
|
|
|
}
|
|
|
- messages = Json.parse(result);
|
|
|
done();
|
|
|
}, function(message) {
|
|
|
Assert.fail(message);
|
|
@@ -64,36 +71,60 @@ class HaxeServerTestCase {
|
|
|
return sys.io.File.getContent("test/templates/" + templateName);
|
|
|
}
|
|
|
|
|
|
- function hasMessage<T>(msg:{kind: String, data:T}) {
|
|
|
- function compareData(data1:Dynamic, data2:Dynamic) {
|
|
|
- return switch (msg.kind) {
|
|
|
- case "reusing" | "notCached": data1 == data2;
|
|
|
- case "skipping": data1.skipped == data2.skipped && data1.dependency == data2.dependency;
|
|
|
- case "print": Std.string(data1).trim() == Std.string(data2).trim();
|
|
|
- case _: false;
|
|
|
- }
|
|
|
- }
|
|
|
- for (message in messages) {
|
|
|
- if (message.kind == msg.kind && compareData(message.data, cast msg.data)) {
|
|
|
+ function hasMessage<T>(msg:String) {
|
|
|
+ for (message in context.messages) {
|
|
|
+ if (message.endsWith(msg)) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ function getStoredType(typePackage:String, typeName:String) {
|
|
|
+ for (type in storedTypes) {
|
|
|
+ if (type.pack.join(".") == typePackage && type.name == typeName) {
|
|
|
+ return type;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
function assertHasPrint(line:String, ?p:haxe.PosInfos) {
|
|
|
- Assert.isTrue(hasMessage({kind: "print", data: line}), null, p);
|
|
|
+ Assert.isTrue(hasMessage("Haxe print: " + line), null, p);
|
|
|
}
|
|
|
|
|
|
function assertReuse(module:String, ?p:haxe.PosInfos) {
|
|
|
- Assert.isTrue(hasMessage({kind: "reusing", data: module}), null, p);
|
|
|
+ Assert.isTrue(hasMessage('reusing $module'), null, p);
|
|
|
}
|
|
|
|
|
|
function assertSkipping(module:String, ?dependency:String, ?p:haxe.PosInfos) {
|
|
|
- Assert.isTrue(hasMessage({kind: "skipping", data: {skipped: module, dependency: dependency == null ? module : dependency}}), null, p);
|
|
|
+ var msg = 'skipping $module';
|
|
|
+ if (dependency != null) {
|
|
|
+ msg += '($dependency)';
|
|
|
+ }
|
|
|
+ Assert.isTrue(hasMessage(msg), null, p);
|
|
|
}
|
|
|
|
|
|
function assertNotCacheModified(module:String, ?p:haxe.PosInfos) {
|
|
|
- Assert.isTrue(hasMessage({kind: "notCached", data: module}), null, p);
|
|
|
+ Assert.isTrue(hasMessage('$module not cached (modified)'), null, p);
|
|
|
+ }
|
|
|
+
|
|
|
+ function assertHasType(typePackage:String, typeName:String, ?p:haxe.PosInfos) {
|
|
|
+ Assert.isTrue(getStoredType(typePackage, typeName) != null, null, p);
|
|
|
+ }
|
|
|
+
|
|
|
+ function assertHasField(typePackage:String, typeName:String, fieldName:String, isStatic:Bool, ?p:haxe.PosInfos) {
|
|
|
+ var type = getStoredType(typePackage, typeName);
|
|
|
+ Assert.isTrue(type != null);
|
|
|
+ function check<T>(type:JsonModuleType<T>) {
|
|
|
+ return switch [type.kind, type.args] {
|
|
|
+ case [Class, c]:
|
|
|
+ (isStatic ? c.statics : c.fields).exists(cf -> cf.name == fieldName);
|
|
|
+ case _: false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (type != null) {
|
|
|
+ Assert.isTrue(check(type), null, p);
|
|
|
+ }
|
|
|
}
|
|
|
}
|