daokoder / dao-modules

Dao Standard Modules
http://daovm.net
12 stars 5 forks source link

Unit testing #68

Open Night-walker opened 9 years ago

Night-walker commented 9 years ago

While daotest is suitable for testing the DaoVM (e.g., it is able to properly test parsing and typing mechanics), I felt the need to have an assertion-based test framework I could use for standard modules. So here it is.

Simple example:

load test
import test.{@test, assertNone, assertEqual}

@test
routine passingTest(){
    assertEqual(2*2, 4)
}

@test('nonsense')
routine failingTest(){
    assertNone(1)
}

@test
routine skippedTest(){
    test.skipTest()
}

routine main(){
    test.runTests()
}

Output:

1. passingTest passed
2. nonsense failed -- line 11: expected none, found 1
3. skippedTest skipped
Summary: 3 tests, 1 passed, 1 failed, 1 skipped

Currently, test.runTest() just dumbly runs all global routines matching prefix. Would be nice if it was possible to sort it out by picking only @test-decorated routines (this issue).

daokoder commented 9 years ago

Nice, this could also be more user friendly for testing applications.

Night-walker commented 9 years ago

Also, line number detection for unexpectedly raised errors is highly desirable. Currently this information is unavailable.

dumblob commented 9 years ago

Also, line number detection for unexpectedly raised errors is highly desirable. Currently this information is unavailable.

Somewhat related to https://github.com/daokoder/dao/issues/298 .

daokoder commented 9 years ago

Also, line number detection for unexpectedly raised errors is highly desirable. Currently this information is unavailable.

Now it is made available.

daokoder commented 9 years ago

BTW, I prefer we rename this module, something like testing, or unitest, or unittest. The reason is that test is such a common name that, when one wants to write something for testing, very likely it will be named as test.dao.

Night-walker commented 9 years ago

Right, testing would be fine.

Night-walker commented 9 years ago

Exception::.line() does not give correct line number. For instance, the example above reports error at line 3 if the new method is utilized.

Night-walker commented 9 years ago

Now there is a problem with the decorator. When I do DaoProcess_Call() on a 'decoratee' of @test (the latter is passed manually to runTests()), it looks like @test itself does not run -- error in a failing test is not caught.