Test files

    To run the test above, use v hello_test.v. This will check that the function hello is producing the correct output. V executes all test functions in the file.

    • Test function names must begin with to mark them for execution.
    • Normal functions can also be defined in test files, and should be called manually. Other symbols can also be defined in test files e.g. types.
    • There are two kinds of tests: external and internal.
    • External tests must import the modules which they test. They do not have access to the private functions/types of the modules. They can test only the external/public API that a module provides.

    In the example above, test_hello is an internal test, that can call the private function hello() because hello_test.v has module main, just like hello.v, i.e. both are part of the same module. Note also that since module main is a regular module like the others, internal tests can be used to test private functions in your main program .v files too.

    • which will be run before all other test functions.
    • testsuite_end which will be run after all other test functions.

    If a test function has an error return type, any propagated errors will fail the test:

    Running tests

    To run test functions in an individual test file, use v foo_test.v.

    You can put additional test data, including .v source files in a folder, named testdata, right next to your _test.v files. V’s test framework will ignore such folders, while scanning for tests to run. This is useful, if you want to put .v files with invalid V source code, or other tests, including known failing ones, that should be run in a specific way/options by a parent _test.v file.

    NB: the path to the V compiler, is available through @VEXE, so a _test.v file, can easily run other test files like this: