JsChilicat: headless Javascript unit testing

One of my Avid colleagues started a Sourceforge project he calls JsChilicat to simplify automated unit testing of Javascript code. The tool invokes the Rhino Javascript engine with the EnvJS and [QUnit][qunit] frameworks on the JS side. EnvJS emulates the browser’s DOM to trick your Javascript into thinking its working in an actual browser. JsChilicat outputs JUnit-compatible XML, including console.log() output. It also does code coverage reports, but I haven’t played with that feature yet. To the best of my Google-fu, this is the only headless Javascript test kit that does code coverage.

The result is brilliant, but a little rough (ExtJS and EnvJS don’t play nice, for example). The documentation is currently insufficient, but just barely so. One or two examples of usage would be enough to reduce this to a half-hour learning curve.

I have no idea where the name comes from… Maybe it’s a pun in German or something? 🙂

Adding NDEBUG to the Xcode Release target

Programmers often want to put behavior in programs that only happens for debug builds, like logging or other diagnostics. A common convention in C is to surround your debug-only behavior with “#ifndef NDEBUG … #endif”. The double-negative is ugly, but it’s a widely used convention nonetheless.

Xcode doesn’t use this convention by default, so you need to add “-DNDEBUG” to your Release compiles to turn off the debugging behavior. To do this, Get Info on your project, go to the “Build” tab, select the “Release” target and edit the Preprocessor Macros line like in the following screenshot.

Screenshot showing Xcode project configuration dialog

(Credit: Greg Parker)

Why Skype fails to save settings

A few times when I upgraded Skype on Windows, it went into a mode where the settings would not stick. I’d have to reset them (like preferring my headset over my speakers) each time I launched Skype. I’m not the only one who experienced this — apparently Skype has an intentional “memory-only” mode where it will not save settings to disk. I don’t know why upgrading triggered the misconfiguration, but here’s the workaround.

The fix is to change this registry setting from “1” to “0”:

[HKEY_LOCAL_MACHINE\Software\Policies\Skype\Phone]
"MemoryOnly"=dword:00000001 

kqueues

FreeBSD (and thus Mac OS X) has a filesystem notification API called kqueues which allow you to autodetect changes in watched files/folders. Apple uses it behind the scenes for indexing (Spotlight). It’s really fast. If I modify a file in one window via “touch /tmp/foo.txt” then the watcher program prints a message in the other window before the touch command exits. I’m using the Obj-C UKKQueue wrapper to simplify access to the kqueue system call.

I’ve found a few cases where the watcher fails to trigger when I rapidly delete and recreate the file… I’m not sure if it’s a bug in the system or in my app (probably the latter, maybe I’m not processing the input fast enough).

[UPDATE: oh, I just learned that kqueue can only watch a file that exists. If I wanted to know when a file was created, I’d have to watch the parent directory and then start watching the file when/if it was created. So that explains my problem with recreates]

In OS X 10.5, Apple added a new FSEvents API which uses a daemon to do a system-wide kqueue for the whole filesystem and distributes the messages to listeners in user space. I expect this is probably to reduce the kernel load of a pile of apps each requesting notifications for the same files.

My current project is targetting 10.4, so I’m avoiding the 10.5-specific FSEvents API.