#!/usr/bin/python
import json
import tap
import sys
separator = "-" * 30

def _tran_stat(res):
    trans_dict = {
        "abort": tap.ERROR,
        "crash": tap.ERROR,
        "fail": tap.FAIL,
        "pass": tap.PASS,
        "skip": tap.SKIP,
        "warn": tap.PASS,
    }
    return trans_dict[res]

writer = tap.TAPGenerator()
json_file = open(sys.argv[1], "r")
with json_file:
    raw_data = json.load(json_file)

print("1..%d" % len(raw_data['tests']))

for result in raw_data['tests']:
    cur_res = raw_data['tests'][result]
    print(writer.format_TAP_msg(_tran_stat(cur_res['result']),
            result, data=cur_res
    ) + "\n")
