List Class in packages

45 views
Skip to first unread message

Jean-Baptiste Richardet

unread,
Mar 4, 2014, 6:05:41 AM3/4/14
to haxe...@googlegroups.com
Hi everyone,

I was wondering if there was a solution to list all the class in a class path.

Practical case, I'm starting to write unit tests and I would like to add test cases in my runner dynamically. Is there a macro or something that's capable of that ?

Thank you,

Jb Richardet

Jason O'Neil

unread,
Mar 4, 2014, 6:09:11 AM3/4/14
to haxe...@googlegroups.com
Hi

My compiletime helper library can pull this off, though there may be a more direct way also:

CompileTime.importPackage("my.package");
for ( cls in CompileTime.getAllClasses("my.package") ) {
var inst = Type.createInstance( cls, [] );
}



--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.

Jean-Baptiste Richardet

unread,
Mar 4, 2014, 6:27:07 AM3/4/14
to haxe...@googlegroups.com, he...@jasono.co
Thank you Jason, that's exactly what I was looking for!

But I just tested it with:
var runner = new Runner();
CompileTime.importPackage("grar.parser");

for ( cls in CompileTime.getAllClasses("grar.parser") ) {
  runner
.addCase(Type.createInstance( cls, [] ));
}      

where "grar.parser" is where my test classes are, I've got the good cp set in my HXML file, but I've got this error:
Error #1034: Type Coercion failed: cannot convert []@114f9c151 to List
    at CompileTimeClassList$/initialise()
    at CompileTimeClassList$/get()
    at RunTest$/main()
    at boot_2fbc/init()
    at flash::Boot/start()
    at boot_2fbc()

Where does this come from ?

Jason O'Neil

unread,
Mar 4, 2014, 6:33:09 AM3/4/14
to haxe...@googlegroups.com
Oh, looks like that code might have broken since I've last used it like that.

I'll take a look now...

Jason O'Neil

unread,
Mar 4, 2014, 6:43:37 AM3/4/14
to haxe...@googlegroups.com
Or I had only ever run tests on neko, which let me get away with a bad cast.

I think I've fixed it now and updated the haxelib, would you like to try again?

Jean-Baptiste Richardet

unread,
Mar 4, 2014, 8:18:09 AM3/4/14
to haxe...@googlegroups.com, he...@jasono.co
Yep, that works fine now! Great job and thanks again for saving me a lot of work :)
Reply all
Reply to author
Forward
0 new messages