   if not cur_test.running()
     # test is over
     mpd.close()
+    runNextTest()
   render()
 
-runTests = ->
-  for test in tests
+runNextTest = ->
+  if test_index < tests.length
     mpd = new Mpd()
-    runTest(test)
+    runTest(tests[test_index++])
 
 $(document).ready ->
   Handlebars.registerHelper 'hash', (context, options) ->

            
            mpd.removeEventListeners 'onPlaylistUpdate'

            lets_test "clear playlist 2"
            mpdEvent 1, 'onPlaylistUpdate', ->
              mpd.removeEventListeners 'onPlaylistUpdate'
              eq mpd.playlist.item_list.length, 0
            mpd.clear()
          mpd.queueFile tracks_to_add[count].file
        mpd.clear()
      mpd.updateArtistInfo random_artist.name
 
    mpd.updateArtistList()
  ->
    lets_test "get current track"
    mpdEvent 1, 'onStatusUpdate', ->
      mpd.removeEventListeners 'onStatusUpdate'
      ok mpd.status.state is "play" or mpd.status.state is "stop" or mpd.status.state is "pause"

    mpd.updateStatus()
  ->
    lets_test "playback buttons"
    # stop playback, so we know where we're at
    mpdEvent 1, 'onStatusUpdate', ->
      mpd.removeEventListeners 'onStatusUpdate'
      eq mpd.status.state, "stop"
    mpd.stop()
]

runTest = (test, args...) ->

          mpdEvent tracks_to_add.length, 'onPlaylistUpdate', ->
            count += 1
            eq mpd.playlist.item_list.length, count
            eq tracks_to_add[count-1].name, mpd.playlist.item_list[count-1].track.name
            eq tracks_to_add[count-1].file, mpd.playlist.item_list[count-1].track.file
            eq tracks_to_add[count-1].time, mpd.playlist.item_list[count-1].track.time
            eq tracks_to_add[count-1].artist, mpd.playlist.item_list[count-1].track.artist

            if count < tracks_to_add.length
              mpd.queueFile tracks_to_add[count].file
