Skip to content

Commit

Permalink
[tests] adjust for macro API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Oct 4, 2023
1 parent c5f56c6 commit d9884b5
Show file tree
Hide file tree
Showing 32 changed files with 130 additions and 122 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(unknown) : Uncaught exception Could not read file define.jsno
$$normPath(::std::)/haxe/macro/Compiler.hx:509: characters 11-39 : Called from here
$$normPath(::std::)/haxe/macro/Compiler.hx:505: characters 11-39 : Called from here
(unknown) : Called from here
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(unknown) : Uncaught exception Could not read file meta.jsno
$$normPath(::std::)/haxe/macro/Compiler.hx:498: characters 11-39 : Called from here
$$normPath(::std::)/haxe/macro/Compiler.hx:494: characters 11-39 : Called from here
(unknown) : Called from here
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(unknown) : Uncaught exception Could not read file meta.jsno
$$normPath(::std::)/haxe/macro/Compiler.hx:498: characters 11-39 : Called from here
$$normPath(::std::)/haxe/macro/Compiler.hx:494: characters 11-39 : Called from here
(unknown) : Called from here
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

| Uncaught exception Could not read file meta.jsno

-> $$normPath(::std::)/haxe/macro/Compiler.hx:498: characters 11-39
-> $$normPath(::std::)/haxe/macro/Compiler.hx:494: characters 11-39

498 | var f = sys.io.File.getContent(path);
494 | var f = sys.io.File.getContent(path);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Called from here

Expand Down
25 changes: 14 additions & 11 deletions tests/misc/projects/Issue3500/Main.hx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
class Main {
static function test() {
var t = haxe.macro.Context.getType("A");
function fail(msg) {
Sys.println(msg);
Sys.exit(1);
}
switch (t) {
case TAbstract(a, _):
var hasTestMeta = Lambda.exists(a.get().impl.get().meta.get(), function(m) return m.name == ":test");
if (!hasTestMeta) {
fail("Abstract implementation class has no @:test metadata");
}
case _:
fail("Should be abstract");
}

haxe.macro.Context.onAfterInitMacros(() -> {
var t = haxe.macro.Context.getType("A");
switch (t) {
case TAbstract(a, _):
var hasTestMeta = Lambda.exists(a.get().impl.get().meta.get(), function(m) return m.name == ":test");
if (!hasTestMeta) {
fail("Abstract implementation class has no @:test metadata");
}
case _:
fail("Should be abstract");
}
});
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions tests/misc/projects/Issue5002/Main3.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import haxe.macro.Context;

class Main3 {
static function init() {
Context.onAfterInitMacros(() -> {
function defineType(name, kind) {
Context.defineType({
pack: [],
name: name,
pos: (macro 0).pos,
kind: kind,
fields: []
});
}

defineType("lowercase", TDClass());

defineType("0_class", TDClass());
defineType("0_enum", TDEnum);
defineType("0_struct", TDStructure);
defineType("0_abstract", TDAbstract(TPath({pack: [], name: "Int"})));
});
}
}
File renamed without changes.
6 changes: 6 additions & 0 deletions tests/misc/projects/Issue5002/compile3-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Main3.hx:10: characters 18-19 : Module "lowercase" does not have a valid name. Module name should start with an uppercase letter: "lowercase"
Main3.hx:10: characters 18-19 : Module "0_class" does not have a valid name. "0_class" is not a valid module name.
Main3.hx:10: characters 18-19 : Module "0_enum" does not have a valid name. "0_enum" is not a valid module name.
Main3.hx:10: characters 18-19 : Module "0_struct" does not have a valid name. "0_struct" is not a valid module name.
Main3.hx:10: characters 18-19 : "0_abstract_Impl_" is not a valid type name.
Main3.hx:10: characters 18-19 : Module "0_abstract" does not have a valid name. "0_abstract" is not a valid module name.
15 changes: 11 additions & 4 deletions tests/misc/projects/Issue7871/Macro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ import haxe.macro.Compiler;
import haxe.macro.Context;

function init() {
var e = macro 42;
Context.typeof(e);
if (Context.defined("haxe")) Context.warning("ok", (macro 0).pos);
Compiler.define("foo", "foo");

Context.onAfterInitMacros(() -> {
Context.warning("after init 1", (macro 0).pos);
Compiler.define("bar", "bar");
var e = macro 42;
Context.typeof(e);
});
Compiler.include("hax.ds", true, true);
Context.onAfterInitMacros(() -> {
Context.warning("after init 2", (macro 0).pos);
});
}

function init_fail() {
var e = macro 42;
Context.typeof(e);
Compiler.define("foo", "foo");

Context.onAfterInitMacros(() -> {
Compiler.define("bar", "bar");
});
}
1 change: 1 addition & 0 deletions tests/misc/projects/Issue7871/compile-1-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--macro Macro.init()
4 changes: 4 additions & 0 deletions tests/misc/projects/Issue7871/compile-1-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Macro.hx:5: characters 60-61 : Warning : ok
Macro.hx:8: characters 42-43 : Warning : after init 1
Package "hax.ds" was not found in any of class paths
Macro.hx:14: characters 42-43 : Warning : after init 2
2 changes: 1 addition & 1 deletion tests/misc/projects/Issue7871/compile-fail.hxml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--macro Macro.init()
--macro Macro.init_fail()
7 changes: 2 additions & 5 deletions tests/misc/projects/Issue7871/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
Macro.hx:7: characters 60-61 : Warning : ok
Macro.hx:11: characters 42-43 : Warning : after init 1
Macro.hx:12: characters 3-32 : Warning : This API should only be used from initialization macros.
Package "hax.ds" was not found in any of class paths
Macro.hx:17: characters 42-43 : Warning : after init 2
Macro.hx:20: characters 2-19 : Cannot use this API from initialization macros.
Macro.hx:20: characters 2-19 : ... Use `Context.onAfterInitMacros` to register a callback to run when context is ready.
2 changes: 0 additions & 2 deletions tests/misc/projects/Issue7871/compile-next-fail.hxml

This file was deleted.

7 changes: 0 additions & 7 deletions tests/misc/projects/Issue7871/compile-next-fail.hxml.stderr

This file was deleted.

50 changes: 26 additions & 24 deletions tests/misc/projects/Issue8019/Macro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,34 @@ import haxe.macro.Context;

class Macro {
static function init() {
function defineType(pack, kind) {
Context.defineType({
pos: (macro 0).pos,
pack: pack,
name: 'Test',
kind: kind,
fields: []
});
}
Context.onAfterInitMacros(() -> {
function defineType(pack, kind) {
Context.defineType({
pos: (macro 0).pos,
pack: pack,
name: 'Test',
kind: kind,
fields: []
});
}

function defineClass(pack) {
defineType(pack, TDClass());
}
function defineClass(pack) {
defineType(pack, TDClass());
}

defineClass(["Module"]);
defineClass(["pack", "Module"]);
defineClass(["Module"]);
defineClass(["pack", "Module"]);

defineClass([""]);
defineClass(["\n"]);
defineClass(["pack\n"]);
defineClass(["pack~"]);
defineClass(["Foo", "Bar"]);

defineClass(["0_class"]);
defineType(["0_enum"], TDEnum);
defineType(["0_structure"], TDStructure);
defineType(["0_abstract"], TDAbstract(TPath({pack: [], name: "Int"})));
defineClass([""]);
defineClass(["\n"]);
defineClass(["pack\n"]);
defineClass(["pack~"]);
defineClass(["Foo", "Bar"]);

defineClass(["0_class"]);
defineType(["0_enum"], TDEnum);
defineType(["0_structure"], TDStructure);
defineType(["0_abstract"], TDAbstract(TPath({pack: [], name: "Int"})));
});
}
}
28 changes: 15 additions & 13 deletions tests/misc/projects/Issue8019/Macro2.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ import haxe.macro.Context;

class Macro2 {
static function init() {
function defineModule(name:String) {
Context.defineModule(name, [{
pos: (macro 0).pos,
pack: [],
name: name,
kind: TDClass(),
fields: []
}]);
}
Context.onAfterInitMacros(() -> {
function defineModule(name:String) {
Context.defineModule(name, [{
pos: (macro 0).pos,
pack: [],
name: name,
kind: TDClass(),
fields: []
}]);
}

defineModule("Valid");
defineModule("Valid");

defineModule("");
defineModule("0");
defineModule("Type+");
defineModule("");
defineModule("0");
defineModule("Type+");
});
}
}
36 changes: 18 additions & 18 deletions tests/misc/projects/Issue8019/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Macro.hx:8: characters 17-18 : "" is not a valid package name:
Macro.hx:8: characters 17-18 : Package name must not be empty
Macro.hx:8: characters 17-18 : "\n" is not a valid package name:
Macro.hx:8: characters 17-18 : Package name must start with a lowercase letter
Macro.hx:8: characters 17-18 : "pack\n" is not a valid package name:
Macro.hx:8: characters 17-18 : Invalid character: \n
Macro.hx:8: characters 17-18 : "pack~" is not a valid package name:
Macro.hx:8: characters 17-18 : Invalid character: ~
Macro.hx:8: characters 17-18 : "Foo" is not a valid package name:
Macro.hx:8: characters 17-18 : Package name must start with a lowercase letter
Macro.hx:8: characters 17-18 : "0_class" is not a valid package name:
Macro.hx:8: characters 17-18 : Package name must start with a lowercase letter
Macro.hx:8: characters 17-18 : "0_enum" is not a valid package name:
Macro.hx:8: characters 17-18 : Package name must start with a lowercase letter
Macro.hx:8: characters 17-18 : "0_structure" is not a valid package name:
Macro.hx:8: characters 17-18 : Package name must start with a lowercase letter
Macro.hx:8: characters 17-18 : "0_abstract" is not a valid package name:
Macro.hx:8: characters 17-18 : Package name must start with a lowercase letter
Macro.hx:9: characters 18-19 : "" is not a valid package name:
Macro.hx:9: characters 18-19 : Package name must not be empty
Macro.hx:9: characters 18-19 : "\n" is not a valid package name:
Macro.hx:9: characters 18-19 : Package name must start with a lowercase letter
Macro.hx:9: characters 18-19 : "pack\n" is not a valid package name:
Macro.hx:9: characters 18-19 : Invalid character: \n
Macro.hx:9: characters 18-19 : "pack~" is not a valid package name:
Macro.hx:9: characters 18-19 : Invalid character: ~
Macro.hx:9: characters 18-19 : "Foo" is not a valid package name:
Macro.hx:9: characters 18-19 : Package name must start with a lowercase letter
Macro.hx:9: characters 18-19 : "0_class" is not a valid package name:
Macro.hx:9: characters 18-19 : Package name must start with a lowercase letter
Macro.hx:9: characters 18-19 : "0_enum" is not a valid package name:
Macro.hx:9: characters 18-19 : Package name must start with a lowercase letter
Macro.hx:9: characters 18-19 : "0_structure" is not a valid package name:
Macro.hx:9: characters 18-19 : Package name must start with a lowercase letter
Macro.hx:9: characters 18-19 : "0_abstract" is not a valid package name:
Macro.hx:9: characters 18-19 : Package name must start with a lowercase letter
6 changes: 3 additions & 3 deletions tests/misc/projects/Issue8019/compile3-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Macro2.hx:7: characters 17-18 : Module "" does not have a valid name. Module name must not be empty.
Macro2.hx:7: characters 17-18 : Module "0" does not have a valid name. "0" is not a valid module name.
Macro2.hx:7: characters 17-18 : Module "Type+" does not have a valid name. "Type+" is not a valid module name.
Macro2.hx:8: characters 18-19 : Module "" does not have a valid name. Module name must not be empty.
Macro2.hx:8: characters 18-19 : Module "0" does not have a valid name. "0" is not a valid module name.
Macro2.hx:8: characters 18-19 : Module "Type+" does not have a valid name. "Type+" is not a valid module name.
22 changes: 0 additions & 22 deletions tests/misc/projects/issue5002/Main3.hx

This file was deleted.

6 changes: 0 additions & 6 deletions tests/misc/projects/issue5002/compile3-fail.hxml.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Main.hx:5: characters 20-24 : Warning : 1
Main.hx:9: lines 9-11 : Warning : This API should only be used from initialization macros.
Main.hx:5: characters 20-24 : Warning : 2
Main.hx:5: characters 20-24 : Warning : 3
Main.hx:5: characters 20-24 : Warning : 4
Expand Down

0 comments on commit d9884b5

Please sign in to comment.