#!/usr/bin/env python

import subprocess
from collections import namedtuple
import os


PerftResult = namedtuple("PerftResult", [
    "nodes",
    "captures",
    "enpassants",
    "castles",
    "promotions",
    "checks",
    "mates"])


start_position_fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
engine = "lesschess"
target = ""


def find_executable():
    global target
    locations = (".", "./build")
    for loc in locations:
        target = loc + "/" + engine
        if os.path.isfile(target):
            return
    raise Exception("Unable to find engine!")


def run_perft_test(fen, depth):
    cmd = '{} perft "{fen}" {depth}'.format(target, fen=fen, depth=depth)
    output = subprocess.check_output(cmd, shell=True)
    nodes, captures, eps, castles, promos, checks, mates = output.split()
    return PerftResult(nodes=int(nodes), captures=int(captures),
                       enpassants=int(eps), castles=int(castles),
                       promotions=int(promos), checks=int(checks),
                       mates=int(mates))


def starting_position_perft_test():
    print "Test: starting position perft...",
    expected = (
            (0, PerftResult(1, 0, 0, 0, 0, 0, 0)),
            (1, PerftResult(20, 0, 0, 0, 0, 0, 0)),
            (2, PerftResult(400, 0, 0, 0, 0, 0, 0)),
            (3, PerftResult(8902, 34, 0, 0, 0, 12, 0)),
            (4, PerftResult(197281, 1576, 0, 0, 0, 469, 8)),
            (5, PerftResult(4865609, 82719, 258, 0, 0, 27351, 347)),
            )
    fen = start_position_fen
    for depth, e in expected:
        run_perft_test(fen, depth)
        res = run_perft_test(fen, depth)
        if res != e:
            print ""
            print "Failed perft test case!!"
            print "FEN: ", fen
            print "Depth: ", depth
            print "Expected: ", str(e)
            print "Actual  : ", str(res)
            return
    print "Passed."


if __name__ == '__main__':
    find_executable()
    starting_position_perft_test()

@@ -79,16 +79,27 @@
 port os%0A
+import sys%0A
 %0A%0APerftR
@@ -359,16 +359,86 @@
  = %22%22%0A%0A%0A
+def iwrite(text):%0A    sys.stdout.write(text)%0A    sys.stdout.flush()%0A%0A%0A
 def find
@@ -1179,21 +1179,31 @@
 est(
-):%0A    print 
+max_depth):%0A    iwrite(
 %22Tes
@@ -1232,13 +1232,11 @@
 erft
-...%22,
+ %22)
 %0A   
@@ -1587,24 +1587,101 @@
 351, 347)),%0A
+            (6, PerftResult(119060324, 2812008, 5248, 0, 0, 809099, 10828)),%0A
             
@@ -1741,16 +1741,64 @@
 pected:%0A
+        if depth %3E max_depth:%0A            break%0A
         
@@ -2113,24 +2113,44 @@
      return%0A
+        iwrite('.')%0A
     print %22P
@@ -2208,16 +2208,16 @@
 table()%0A
-
     star
@@ -2241,10 +2241,11 @@
 ft_test(
+5
 )%0A

Add a progress bar on testsuite