I noticed haxe.unit has been removed from Haxe 4’s standard library when I was greeted with this message trying to run unit tests:
Test.hx:1: characters 7-24 : Type not found : haxe.unit.TestCase
I understand the logic behind removing it from core, and https://github.com/HaxeFoundation/hx3compat was one way to address compatibility (although you have to know it exists.) I’d like to suggest an alternative way to go about its removal, which hopefully can be used in the future on additional cleanup. I can point to OpenFL’s NMEPreloader deprecation as a great example of handling deprecation carefully. The important difference is that there’s an explicit transition phase, where both ways will work, before we remove one of them.
I’d like to see what people think. If the argument is “we should but we don’t have time”, I volunteer to make the change myself
Step 1: Copy (don’t move) the package to a new library
Either put it in “hx3compat” or create a new “HaxeFoundation/unit” and copy the haxe.unit package there. (It’s possible to split files out of a git repo while maintaining their history.) The package now exists in both places.
Step 2: Apply a standard deprecation mechanism to haxe.unit.* types
If anyone uses
haxe.unit.* from the main repo without including the new split out library, they should be shown a compiler warning; however, their tests should still compile and work. There are a couple ways to do this; OpenFL and HaxePunk have both done it in the past. Clearly deprecate it in the docs as well with the same hint.
The warning should specify exactly how to fix the problem: run “haxelib install hx3compat” and include it when you compile.
If you’re using the external version, it will shadow the std lib package and you won’t see the warning.
Step 3: Remove it later, in the next major version
When people have had plenty of time to make the switch, you can go ahead and remove the package from core.