Skip to content
This repository
tree: 1e86bb17e8
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 75 lines (57 sloc) 2.021 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#!/usr/bin/env python
#vim: set filetype=python

import subprocess
import sys
import os

def execute(commandline):
    proc = subprocess.Popen(commandline.split(" "), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = proc.communicate()
    sys.stdout.write(out)
    sys.stdout.write(err)
    return (proc.returncode, out, err)

def notify(text, color):
    cmd = ["/usr/bin/osd_cat", "-A", "right", "-d", "2", "-c", color]

    if os.fork() == 0:
        subprocess.Popen(cmd, stdin=subprocess.PIPE).communicate(text)
        sys.exit(0)

def getFirstLine(text, predicate):
    return filter(predicate, text.split("\n"))[0]

def isBuildError(line):
    return line.startswith("src/Ocram") or line.startswith("test/Ocram")

def isTestError(line):
    return line.startswith('### Failure in:')

def diff_code(text):
    expected = []
    got = []

    for line in text.split("\n"):
        if line.startswith("expected:") and line.count('"') == 2:
            (pre, code, post) = line.split('"')
            expected.append(code)
        if line.startswith(" but got:") and line.count('"') == 2:
            (pre, code, post) = line.split('"')
            got.append(code)
            
    assert len(expected) == len(got), str(expected) + "\n" + str(got)

    def paste(name, code):
        f = open(name, "w")
        f.write(code.replace(r'\n', '\n'))
        f.close()

    inf = "/tmp/infile.c"
    outf = "/tmp/outfile.c"

    for (ins, outs) in zip(got, expected):
        print "----- diff"
        paste(inf, ins)
        paste(outf, outs)
        
        proc = subprocess.Popen(["wdiff", inf, outf])
        proc.wait()

(code, out, err) = execute("runhaskell Setup.hs build")
if code != 0:
    open("./.quickfix", "w").write(err)
    notify(getFirstLine(err, isBuildError), "red")
    sys.exit(1)

(code, out, err) = execute("./dist/build/Test/Test")
if code != 0:
    notify(getFirstLine(err, isTestError), "red")
    diff_code(err)
    sys.exit(1)

notify("success", "green")
sys.exit(0)
Something went wrong with that request. Please try again.