A Grey Hack unit testing framework
Find a file
Volk b3d547d3d2 dev (#2)
Reviewed-on: #2
2026-02-11 12:10:52 +01:00
src added from other repo 2026-02-10 22:26:57 +01:00
.gitattributes added from other repo 2026-02-10 22:26:57 +01:00
.gitignore added from other repo 2026-02-10 22:26:57 +01:00
example.png added from other repo 2026-02-10 22:26:57 +01:00
LICENSE Initial commit 2026-02-10 22:21:21 +01:00
main.src added from other repo 2026-02-10 22:26:57 +01:00
README.md dev (#2) 2026-02-11 12:10:52 +01:00

GreyTest

Unit testing framework for Grey Hack (game). GreyTest provides a lightweight, focused API to write and run unit tests for in-game scripts and libraries used within Grey Hack.

Features

  • Test definitions that run inside Grey Hack-compatible environments
  • Assertions for values, maps, and functions
  • Simple CLI-style runner with pass/fail counts and minimal output suitable for in-game consoles
  • Seperate runner for each test showing exactly which test failed and why

Example image

Screenshot

Setup

  1. Import the framework into your codebase before any code execution.
    It is recommended to this using the vscode plugin made by ayecue.
    #include "/path/to/framework"
    
  2. Creating a test
    First a test object is created using the create function.
    After this the actual test run function is defined.
    __TEST__.create("myFunction") -- Adding false as a second argument will skip this test.
    __TEST__.tests["myFunction"].run = function
        self.assertEq(myFunction("string.to.split"), ["string","to","split"])
    end function
    
    To skip a function simply add a 0 as an extra argument like so.
    __TEST__.create("myFunction", 0) -- This is a skipped test.
    
  3. Running the tests
    In order to run the tests __TEST__.run is called.
    It is important for this to be run before the main function of the program.
    This is, because the tests need to be run before the program starts.

Assert functions

Here is a list of all the assert functions:

assertEq(actual, expected)      --tests if the actual is equal to expected.
assertNotEq(actual, expected)   --tests if the actual is not equal to expected.
assertIsa(actual, expected)     --tests if the actual is of the same type as expected.
assertNotIsa(actual, expected)  --tests if the actual is not of the same type as expected.
assertBigger(actual, expected)  --tests if the actual is bigger than expected.
assertSmaller(actual, expected)  --tests if the actual is smaller than expected.
assertBigEq(actual, expected)   --tests if the actual is bigger or equal to expected.
assertSmallEq(actual, expected) --tests if the actual is smaller or equal to expected.
assertTrue(actual)              --tests if the actual is true.
assertFalse(actual)             --tests if the actual is false.
assertNull(actual)              --tests if the actual is null.
assertNotNull(actual)           --tests if the actual is not null.