SKILL Test Framework#
The Test module defines a testing framework modelled after the Python PyTest tool.
The built-in assert is used for testing
test function names start with ‘test_’
Test setup fixtures are defined with input parameters.
Additional Test setup fixtures can be added to the Test->Fixtures table.
The Test->Run function should be called at the end of each test script so the tests run when the script is loaded. Each test case is defined as a function that uses the built-in assert statement to test the code. A function is considered passing if it doesn’t throw an error.
Example test script
1 let(((Str Import['Str])
2 (Test Import['Test])
3 (Virtue Import['Virtue])
4 )
5
6 procedure(Test_emptyp()
7 assert(Str->emptyp(""))
8 assert(!Str->emptyp("test"))
9 )
10
11 procedure(Test_str2bool()
12 assert(Str->str2bool("true"))
13 assert(Str->str2bool("TRUE"))
14 assert(!Str->str2bool("false"))
15 )
16
17 procedure(Test_str2bool_error()
18 assert(!errset(Str->str2bool("Nothing")))
19 )
20
21 Test->RunFile(list(nil
22 'Test_emptyp Test_emptyp
23 'Test_str2bool Test_str2bool
24 'Test_str2bool_error Test_str2bool_error
25 )
26 ?filepath Virtue->GetCurrentFilePath()
27 )
28
29 )
The Test->RunDirectory(test_dir_path) function will run all the test scripts in a directory and report the results of them all.
run_tests.ils
1let((dir_path
2 (Test Import['Test])
3 (Virtue Import['Virtue])
4 (Str Import['Str])
5 )
6
7dir_path = Virtue->GetCurrentFileDirectory()
8Test->RunDirectory(dir_path)
9)
The testing framework also includes test setup fixtures which can be called by adding the name of the fixture function to a test case:
TestFixtures.ils
1let(((Test Import['Test])
2 (Virtue Import['Virtue])
3 )
4
5procedure(test_TempDirectory(TempDirectory)
6 assert(isDir(TempDirectory))
7)
8
9Test->RunFile(list(nil
10 'test_TempDirectory test_TempDirectory
11 )
12 ?filepath Virtue->GetCurrentFilePath()
13)
14
15)
Additional test fixtures can be added by adding them to the Test->Fixtures table:
TestFixtures.ils
1let(((Test Import['Test])
2 (PathConcat Import['Path]->Concat)
3 (Fixtures makeTable("Test Fixtures"))
4 )
5 procedure(TempDirectory(@optional (path_prefix "virtue") "t")
6 let((temp_filepath)
7 temp_filepath = makeTempFileName(PathConcat(getTempDir() path_prefix))
8 createDirHier(temp_filepath)
9 temp_filepath
10 ))
11
12 Fixtures['TempDirectory] = TempDirectory
13 putprop(Test Fixtures 'Fixtures)
14)