Ensure that a Haxe program will run on all platfor

2020-07-24 16:18发布

问题:

I plan to write Haxe libraries in a subset of Haxe that will compile to every Haxe target language. Is there any way to verify that a Haxe program will compile to all target languages, and is it possible to do this without manually testing the compiled code on each target platform?

For example, is there a way to ensure that the following code is valid on every target platform, without testing it manually on every single platform?

  class Test {
  static function main(){
    trace("How can I check to see which platforms this program will run on?");
  }
}

EDIT: I have written a compile.hxml file that compiles the class Test.hx to various target languages. All the necessary haxelib libraries will need to be installed first in order for it to work properly.

-js test.js
-main Test

--next
-php www
-main Test

--next
-cpp cpp
-debug
-main Test

--next
-main Test
-java java

--next
-cs test
-main Test
-D haxe3

回答1:

I have done some similar things with a few of my libraries (mdown and detox), and I was able to test several of the platforms using MUnit / MassiveUnit:

https://github.com/massiveinteractive/MassiveUnit

This is a unit testing platform that you can use to check your behaviour across multiple targets. There is also utest, and possibly others.

Currently munit can automatically run tests for your code on the following targets:

  • Neko
  • Flash 8
  • Flash 9+
  • Javascript
  • CPP

There are instructions for adding support for other targets here

(If you don't know much about unit testing - it's a way to write lots of small tests to make sure your library/code behaves as expected, and is perfect for checking that things function across platforms, as well as making sure you don't break things when you change your code.)



标签: haxe