Archive

Archive for the ‘Tools’ Category

Vala and unit testing

January 23, 2009 Ali Sabil 5 comments

During the past year, I have been writing most of my code in Vala, an awesome, simple and beautiful language. When I started using it, the implementation was still in its infancy, and had a pretty high number of bugs, and the only way to make sure that the code produced by the compiler was good, was to write unit tests. The first attempt was made by Johann Prieur, in the form of vunit, a mostly direct port of junit 3.x, which turned into vtest later, and also got forked into another vunit :D In the end I wrote a very simplistic unit testing framework that serves my need: test-it.

But that wasn’t really enough for me. Few days ago I cooked a small patch that would help simplifying the process of writing unit tests in Vala. The patch allows writing unit test suites like this:

[Test (path = "/vala/foo/bar")]
class FooBarTest {
	private StringBuilder buffer;

	public void set_up () {
		buffer = new StringBuilder ();
	}

	public void tear_down () {
		buffer = null;
	}

	public void test_1 () {
		buffer.append ("hello");
		assert (buffer.str == "hello");
	}

	public void test_2 () {
		assert (buffer.str == "");
	}
}

int main (string[] args) {
	Test.init (ref args);

	var o = new FooBarTest ();

	Test.run ();
	return 0;
}

Vala, would then notice the [Test] attribute for the FooBarTest class, and produce a set of test cases that get registered with GTest when the class is instanciated. When compiled and ran the previous code produces the following output:

$ ./testing
/vala/foo/bar/1: OK
/vala/foo/bar/2: OK

The patch is still far from perfect, and personally I don’t really appreciate GTest, but if you feel like improving it, feel free to grab the code from here:

bzr branch lp:~asabil/+junk/vala-gtest-module

Categories: People Framework, Tools, Vala

bzr-interactive

March 8, 2008 Ali Sabil Leave a comment

 Yesterday I updated the bzr-record plugin and renamed it to bzr-interactive. The name change comes from the fact that the plugin aims at adding support for user interactivity for the core commands in a similar fashion to Darcs. For now bzr-interactive only supports the commit command.

The plugin works by adding a –interactive (-i) option to the supported commands. For the commit command, running bzr commit -i will prompt you for the hunks you want to commit in an interactive manner, and also prompt you for the commit message. I hope to add support for other commands in the future, especially for the merge command (cherry-picking :p).

Concerning the record-patch command, it works by asking which hunks you want to save into a patch, the patches are saved in the patches/ subdirectory, and should be easily manageable using quilt. I would however suggest using bzr-loom instead, if your goal is upstream tracking.

Categories: Free Software, Tools, bzr Tags: , , ,

oSpy Stream HTML converter

February 15, 2007 Ali Sabil 1 comment

Today I managed to produce a finally working version of oSpy Stream HTML converter, which is basically a python script that takes an xml file generated by oSpy Visualizer and produces a (nice looking ?) HTML file out of it.

The script is not complete and still lacks “timelining” but still usable :) You can grab it using bzr :

bzr get http://projects.collabora.co.uk/~asabil/bzr/oSpyStream2HTML/

Then you can try it :
python stream2html.py sample.xml > sample.html

Happy oSpying ^_^

Categories: Tools