#97integrated unit testing

  • avatar~clovercommented · 2 years ago
    Author
    Owner

    in module scope you can add test declarations, similar to Zig

    fn add(a: int, b: int) void { a + b }
    
    test "named test" {
      assert add(1, 4) == add(4, 1);
    }
    
    // "doctest" refer to the thing your are testing directly
    // documentation generator will use this for showing code
    // examples next to a declaration.
    test add {
      assert add(5, 2) == 7;
    }
    

    the assert keyword already exists (not implemented in sema). unlike zig, i don't want to add test as a keyword. but only in module scope at the start of a statement, it will act like one. this means you can do this:

    fn test {
      std.log.info("hello");
    
      let test = 1;
      test
    }
    
    // the test case for 'test'
    test test {
      assert test() == 1;
    }
    

    a proper cli does not yet exist, but the test runner should ideally run tests on all threads. each test runs in isolation to each other, regarding global state.

    something else to consider is making it easy to mock IO with tests, though this will probably just be a feature of the standard library.


    Milestone: 0.3.0.

  • avatar~clover changed the status to Todo · 2 years ago