A small Vala helper library for writing and registering GLib tests with less boilerplate.
- Features
- Public API (summary)
- Example test suite
- Use In Other Projects
- Quick init (dependency setup)
- Build
- Test
- Dependencies
- License
- Simple base class for test registration
- Wrapper for registering test suites by type
- Compatible with GLib test runner (
Test.run()) - Designed for Meson subproject integration
Namespace: ValaTux.Testcases
BaseTestadd_test(string name, owned TestCommand.TestMethod method)
register_test_suite<T>()
using GLib;
using Gee;
namespace AppTests {
using ValaTux.Testcases;
public class ExampleTest : BaseTest {
construct {
add_test ("math", test_math);
add_test ("text", test_text);
}
public void test_math () {
assert (1 + 1 == 2);
}
public void test_text () {
assert ("vala".length == 4);
}
}
}
int main (string[] args) {
ValaTux.Testcases.BaseTest.saved_commands = new Gee.ArrayList<ValaTux.Testcases.TestCommand> ();
Test.init (ref args);
ValaTux.Testcases.register_test_suite<AppTests.ExampleTest> ();
return Test.run ();
}Yes. The generated artifacts are intended for reuse:
build-release/src/libvala_testcases.so*build-release/src/vapi/vala_testcases.vapibuild-release/src/vala_testcases.h
In your consumer project meson.build:
vala_testcases_dep = dependency('vala_testcases', fallback: ['vala_testcases', 'vala_testcases_dep'])
executable('my-tests',
['tests/main.vala', 'tests/example_test.vala'],
dependencies: [dependency('glib-2.0'), dependency('gee-0.8'), vala_testcases_dep],
)Then in Vala code:
using ValaTux.Testcases;Install this project first:
meson setup builddir
meson compile -C builddir
meson install -C builddirIn your consumer meson.build:
vala_testcases_dep = dependency('vala_testcases', method: 'pkg-config')Install via Vamposer
In your consumer project root:
vamposer require --dev ValaTux/testcases master
vamposer install --devThen include generated Vamposer dependencies in your meson.build:
subdir('vamposer')
executable('my-app',
sources,
dependencies: [
vamposer_deps
]
)You can also use a fixed tag or commit instead of master.
If you want everything vendored inside your own repository, copy release artifacts into your consumer project, for example:
your-project/vapi/vala_testcases.vapiyour-project/lib/libvala_testcases.soyour-project/include/vala_testcases.h
To automate this setup, run the helper script in your consumer project root:
curl -sSfL https://raw.githubusercontent.com/ValaTux/testcases/master/init-local-vapi.sh | bashThe script will:
- download a prebuilt release ZIP when available (fast path)
- fallback to building
vala-testcasesfrom source when release assets are unavailable - copy artifacts into your local
vapi/,lib/, andinclude/directories - append an idempotent helper block to your
meson.buildwith reusable variables
You can also run it from a local file copy:
./init-local-vapi.shThen configure your consumer meson.build:
executable('my-tests',
['tests/main.vala', 'tests/example_test.vala'],
dependencies: vala_testcases_local_deps,
vala_args: vala_testcases_local_vala_args,
c_args: vala_testcases_local_c_args,
link_args: vala_testcases_local_link_args,
)And load the shared library at runtime, for example:
LD_LIBRARY_PATH=./lib ./my-testsTo add vala-testcases as a Meson subproject dependency, run:
./init.shOr run it directly from GitHub:
curl -sSfL https://raw.githubusercontent.com/ValaTux/testcases/refs/heads/master/init.sh -o init.sh && chmod +x init.sh && ./init.sh && rm init.shFor local vendored integration without subprojects, use:
curl -sSfL https://raw.githubusercontent.com/ValaTux/testcases/master/init-local-vapi.sh | bashmeson setup builddir
meson compile -C builddirmeson test -C builddiror via Makefile helper:
make tests- glib-2.0
- gee-0.8
In consumer projects, use:
vala_testcases_dep = dependency('vala_testcases', fallback: ['vala_testcases', 'vala_testcases_dep'])Then add vala_testcases_dep to your target dependencies.
MIT (see LICENSE).