› cmake

» Shell helper: running KDE unit tests (ctests) the easy way
Thu, 03/26/2009 - 03:09
Unit tests are in my eyes a very important part of programming. KDE uses them, KDevelop does - the PHP plugin I help writing does as well. cmake comes with a ctest program which does quite well to give you a quick glance on which test suite you just broke with your new fance feature :)
But I am very dissatisfied with it. Right now I usually do the following
# lets assume I'm in the source directory cb && ctest # look for failed test suites cd $failed_test_suite_path ./$failed_test_suite.shell | less # search for FAIL cs cd $to_whereever_I_was_before
That’s pretty much for just running a test. Especially all that cding and lessing became very tedious. Tedious is good, because I eventually fix it:
introducing kdetest
I wrote a bash function (with autocompletion!!!) called kdetest. Calling it without any parameter will run all test suites and gives a nice report of failed functions at the end. Here’s an example (run via cs php && kdetest).
kdetest # ... lots of test output --- ALL PASSED TESTS --- ... PASS : Php::TestCompletion::implementMethods() PASS : Php::TestCompletion::inArray() PASS : Php::TestCompletion::cleanupTestCase() 143 passed tests in total --- ALL FAILED TESTS --- FAIL! : Php::TestCompletion::newExtends() Compared values are not the same FAIL! : Php::TestCompletion::updateExtends() '! forbiddenIdentifiers.contains(item->declaration()->identifier().toString())' returned FALSE. () FAIL! : Php::TestCompletion::updateExtends() '! forbiddenIdentifiers.contains(item->declaration()->identifier().toString())' returned FALSE. () FAIL! : Php::TestCompletion::updateExtends() Compared values are not the same FAIL! : Php::TestCompletion::newImplements() Compared values are not the same FAIL! : Php::TestCompletion::updateImplements() Compared values are not the same 6 failed tests in total
usage
kdetest, i.e. without any arguments runs all tests in this directory and belowkdetest path/to/test.shell ...runs that test suite only,...can by any argument the test suite accepts.
autocompletion
kdetest comes with full support for autocompletion of tests and functions, for example:
milian@odin:~/projects/kde4/php$ kdetest TABTAB completion/tests/completiontest.shell duchain/tests/expressionparsertest.shell parser/test/lexertest.shell duchain/tests/duchaintest.shell duchain/tests/usestest.shell milian@odin:~/projects/kde4/php$ kdetest duchain/tests/usestest.shell TABTAB classAndConstWithSameName classSelf interfaceExtendsMultiple staticMemberFunctionCall classAndFunctionWithSameName constAndVariableWithSameName memberFunctionCall staticMemberVariable classConstant constant memberFunctionInString variable classExtends constantInClassMember memberVariable variableTwoDeclarations classImplements functionAndClassWithSameName memberVarInString variableTwoDeclarationsInFunction classImplementsMultiple functionCall newObject varInString classParent interfaceExtends objectWithClassName
the code
You can find the code below, or you can obtain the most up-to-date version on github. Just head over to my shell-helpers repo and peek into the bash_setup_kde4_programming file.
» Building KDevplatform, KDevelop and the PHP plugin from SVN
Fri, 03/06/2009 - 01:21
In a follow up to my last post about the PHP plugin for KDevelop and Quanta I want to detail how I setup my build environment. Since I’m only working on KDevelop I only want to compile that. For all other applications, I use the packages my distribution makes available. Below you this is possible.
Note: I use Kubuntu and hence some commands like aptitude and the package names etc. will have to be adapted to your specific distribution. But the general idea should be the same and the packages should be called at least somewhat similar. You could always take a look at the techbase article on compilation of KDE 4 to get a more general HowTo.
It is generally a very good idea to read some articles on the techbase. Especially in the Getting Started section.
getting the dependencies
First, you’ll need to install some packages to satisfy dependencies and to get a working compile chain (think cmake, gcc and stuff). The following command only lists very few packages but they have a huge list of dependencies which your package manager will take into account automatically. Don’t be suprised by a possibly huge list of packages ;-) So some disk space will be required (though I doubt it’s more than 250MB in total).
Note: You’ll need the KDE 4.2.x versions of the KDE libraries and development packages. When you use Kubuntu, you can follow this article to get up to date packages for the 8.10 release.
# I hope these are all, it's been a time since I did that the last time # please report if anything is missing aptitude install kdebase-dev kdelibs5-dev kdebase-workspace-dev \ libqt4-dev build-essential subversion kdesdk-scripts
removing old cruft
To prevent binary compatibility issues that will result in crashes, you have to remove all KDevelop & KDevplatform packages provided by your package maintainer. In karmic it should be enough to remove kdevplatform, and it will remove all dependent packages:
aptitude remove kdevplatform
setting up your environment
Inspired by the techbase article on improved productivity in KDE4, particularly the bashrc listed there, I’ve come up with the following way to configure my system:
First visit my shell helper git repo on GitHub and download the two files kde4_setup_build_environment.sh and bash_setup_kde4_programming.
set the environment variables
Move the file kde4_setup_build_environment.sh to ~/.kde/env and make it executable. You might want to adapt the paths for the variables KDE_BUILD, KDE_SRC and KDEDIR inside that file to your likings.
This part is required to make sure that compiled programs will act just like normal programs installed globally (e.g. with your package manager) right from the start of your KDE session. I.e. KRunner works fine and custom plugins are found etc.
make your life easier with some bash magic
Now alter your ~/.bashrc and to the bottom of that file add the following line:
. ~/.bash_setup_kde4_programming
NOTE: This assumes that you saved the afore mentioned bash_setup_kde4_programming file to ~/.bash_setup_kde4_programming. You might have to change the path.
NOTE: That file also sources the above script to set the environment variables. I’m not sure it’s required, but it doesn’t hurt. So make sure the path is correct there.
Now to the fun part
Once all that’s done, you have to log out of your bash session to get the environments. Maybe even logout of your KDE session to make it aware of the new paths as well.
checking out KDevplatform, KDevelop and the PHP plugin
Get the latest and greatest directly from SVN (see also Using Subversion with KDE on techbase):
cs # cs is not a typo! see above svn co svn://anonsvn.kde.org/home/kde/trunk/extragear/sdk/kdevplatform svn co svn://anonsvn.kde.org/home/kde/trunk/extragear/sdk/kdevelop svn co svn://anonsvn.kde.org/home/kde/trunk/extragear/sdk/kdevelop-plugins/php svn co svn://anonsvn.kde.org/home/kde/trunk/extragear/sdk/kdevelop-plugins/php-docs
compiling and installing
Now it’s time to compile all that code you just checked out. Hopefully you got all required dependencies. If you need all bells and whistles, you’ll have to install some more packages I’m sure. If you run the code below, take a good look at the output of the cmakekde command (especially at the beginning). It lists not-found dependencies.
Note: cmakekde is supposed to be run from inside your source folder (e.g. cs $FOLDER; cmakekde).
cs kdevplatform cmakekde cs kdevelop cmakekde cs php cmakekde cs php-docs cmakekde kbuildsycoca4 # make sure new plugins etc. are found
Pretty easy, hum? Let’s hope everything worked fine :)
staying up to date
That above command is only required once. Everytime after that, you can simply do the following which will make sure you are running the latest and greatest:
cs kdevplatform svn up && make install cs kdevelop svn up && make install cs php svn up && make install
The End
Hope I have not forgotten anything and that this (rather lengthy…) HowTo is of some help to a few of you out there. Looking forward to feature requests, bug reports etc.
UPDATE 08/01/10: updated to extragear location of php & php-docs
UPDATE 01/12/09: added php-docs, updated to extragear location of kdevplatform & kdevelop.
UPDATE 17/12/09: updated to kdereview location of php & php-docs