Skip to content
  • Yorick Peterse's avatar
    Add support for writing unit tests · 6719779a
    Yorick Peterse authored
    This commit adds support for writing unit tests using the "std::test"
    module. Using this module we can write unit tests using a simple API,
    inspired by other unit testing frameworks such as RSpec. For example,
    writing a test for Integer.== could be done as follows:
    
        import std::test
        import std::test::assert
    
        test.group 'Integer.==', do (group) {
          group.test 'Comparing two integers that are identical', {
            try assert.equal(10, 10)
          }
        }
    
    Tests are executed concurrently, with a default of 32 concurrent tests.
    Changing this (and other settings) can be done as follows:
    
        import std::test
    
        test.configure('concurrency', 16)
    
    With this change comes a slight reorganisation of the "runtime"
    directory. The new structure is as follows:
    
    * runtime: the root directory of the runtime. This is basically a
      project on its own, just like the VM and the compiler.
    * runtime/src: the source code of the runtime.
    * runtime/tests: the top-level directory for tests
    * runtime/tests/test: the top-level namespace for all tests. Every
      project will place their tests in the directory "tests/test".
    * runtime/tests/main.inko: the main test file that will be executed when
      running "inko-test"
    
    The directory structure of "tests/test" mirrors the "src" directory.
    This means that tests for "std/integer.inko" can be found in
    "tests/test/std/test_integer.inko".
    
    Test files use a "test_" prefix to allow distinguishing them from any
    support modules. This means that you can import tests as follows:
    
        import test::std::test_integer
    
    Currently test files need to be imported manually into tests/main.inko.
    This is cumbersome, but for now this is the most simple way of getting
    things to work.
    
    To make it easier to run tests the compiler provides an executable
    called "inko-test". Using this executable we can run Inko's own tests
    like so:
    
        inko-test -d runtime --vm vm/target/release/ivm
    
    Once the Inko compiler is self hosting, we can replace all of this Ruby
    code with just Inko source code, and hopefully import test modules
    automatically.
    6719779a