sbrl / Minetest-WorldEditAdditions

Extra tools and commands to extend WorldEdit for Minetest
https://worldeditadditions.mooncarrot.space/
Mozilla Public License 2.0
16 stars 3 forks source link

Unit testing #40

Closed sbrl closed 3 years ago

sbrl commented 3 years ago

There comes a point in every project that one realises that some tests might assist in ensuring correct functionality. It's perhaps not a particularly fun task, but definitely worth doing.

We should implement some tests for WorldEditAdditions, starting with the contents of the utils directory.

The reason for this is that recently a number of bugs have come to light regarding the utilities we've implemented, which could have been avoided if we had tests for them.

Testing the world-modifying functionality itself that calls the Minetest/WorldEdit APIs is very complicated and out-of-scope of this issue - not least of which because all the Minetest API calls would have to be refactored out of the existing worldeditadditions core API codebase.

u-test appears as though it'll do the job nicely and supports inclusion via a git submodule too (which would be our preference I think), however we'd need to work out how we'd do that since Minetest would consider it to be a mod and try to load it.

I'd suggest here that we have a testssubdirectory inside the worldeditadditions mod directory that we put all the tests stuff in. Other mods in the modpack can have their own tests subdirectory if desired, but with a symlink to the u-test git submodule in worldeditadditions/tests perhaps.

VorTechnix commented 3 years ago

How do you plan on handling cases where the functions you (maybe we... I'd be willing to help as I have time) are going to test with this u-test thing call or rely on worldedit or worse minetest specific functions/objects?

sbrl commented 3 years ago

Hrm, that's an awkward one. I intend to mock those bits, but I've been thinking sincce I opened this issue and actually we could really do with refactoring utils altogether. Some of the files are getting quite long, and I suspect that splitting some of them up might do some good. The intention I think would be to move to a lib folder instead with things categorised into directories instead - that way can split them up more.

It's a bit frustrating there isn't a way to do it more like Javascript, in that we can import the utilities we need into each file, rather than having to attach them all to the global worldeditadditions object.

I'm still thinking about this though, so thoughts?

VorTechnix commented 3 years ago

We're probably just going to have to hack it. By that I mean just make tables that return the values needed by the functions. Unless of course we could get our hands on the actual minetest lua library.

sbrl commented 3 years ago

Yep, that's probably the plan. It's called mocking, and it's the way you're supposed to do it in scenarios like this. We'll start with the easy ones though that don't have dependencies :P

sbrl commented 3 years ago

Unit testing has now been implemented! We have yet to automate and improve coverage, but that's an issue for another time. I'll close this for now - any further issues with the unit testing system should be discussed in a new issue.