| 22 | } |
| 23 | |
| 24 | def run_test(t): |
| 25 | global total, ok, fail, expected_fail |
| 26 | total += 1 |
| 27 | c = glob.glob(t + "/cursor.*")[0] |
| 28 | cursorpos = os.path.splitext(c)[1][1:] |
| 29 | try: |
| 30 | with open(t + "/out.expected", "r") as f: |
| 31 | outexpected = f.read() |
| 32 | except: |
| 33 | outexpected = "To be determined" |
| 34 | filename = t + "/test.go.in" |
| 35 | gocode = subprocess.Popen(["gocode", "-in", filename, "autocomplete", filename, cursorpos], |
| 36 | shell=False, stdout=subprocess.PIPE) |
| 37 | out = gocode.communicate()[0] |
| 38 | if out != outexpected: |
| 39 | if t in expected_to_fail: |
| 40 | print t + ": " + FAIL + " " + EXPECTED + expected_to_fail[t] |
| 41 | expected_fail += 1 |
| 42 | else: |
| 43 | print t + ": " + FAIL |
| 44 | print "--------------------------------------------------------" |
| 45 | print "Got:\n" + out |
| 46 | print "--------------------------------------------------------" |
| 47 | print "Expected:\n" + outexpected |
| 48 | print "--------------------------------------------------------" |
| 49 | fail += 1 |
| 50 | else: |
| 51 | print t + ": " + OK |
| 52 | ok += 1 |
| 53 | |
| 54 | if len(sys.argv) == 2: |
| 55 | run_test(sys.argv[1]) |