Пример #1
0
def _import_js(html_string, fe_path, go):
    import_script = "<script type=\"text/javascript\" src=\"{0}\"></script>"
    last_import = []
    for cssfile in ["styles.css", "styles_inv.css", "styles_src.css", "jquery-ui-1.12.1.min.css"]:
        from_sys_call_enforce(" ".join(["cp", fe_path + cssfile, go + cssfile]))
    for jslib in ["jquery-3.1.1.min.js", "jquery-ui-1.12.1.min.js", "jquery.simpletip-1.3.2.js",
                  "buckets.min.js", "run_prettify.js", "getty.js"]:
        from_sys_call_enforce(" ".join(["cp", fe_path + jslib, go + jslib]))
        last_import.append(import_script.format(jslib + "?ver=" + config.version_time))
    last_import.append("</body>")
    last_import_str = "\n".join(last_import)
    return html_string.replace("</body>", last_import_str)
def is_different(target, go, prev_hash, post_hash):
    tfs = fsformat(target)
    prev_invs_file = go + "_getty_inv__" + tfs + "__" + prev_hash + "_.inv.out"
    post_invs_file = go + "_getty_inv__" + tfs + "__" + post_hash + "_.inv.out"
    if (not os.path.exists(prev_invs_file)) or (not os.path.exists(post_invs_file)):
        return True
    difftext = from_sys_call_enforce(" ".join(["git diff", prev_invs_file, post_invs_file]))
    if difftext == "":
        return False
    else:
        return True
def junit_torun_str(cust_mvn_repo):
    if config.no_mvn_customization:
        extract_cmd = "mvn test -q | grep ^Running\ *"
        print '\nRunning tests to get all test & test cases ...'
        cmd_output = from_sys_call_enforce(extract_cmd).strip()
        filtered = []
        matching = "Running (.*)"
        for candidate in cmd_output.split('\n'):
            m = re.match(matching, candidate.strip())
            if m and len(m.groups()) > 0:
                filtered.append(m.group(1).strip().split(' ')[0])
        return " ".join(["org.junit.runner.JUnitCore"] + filtered)
    else:
        local_repo = ""
        if config.effortless_mvn_setup:
            local_repo = "-Dmaven.repo.local=" + cust_mvn_repo
        mvn_cmd = "mvn " + local_repo + \
            " org.apache.maven.plugins:maven-surefire-plugin:2.19.2-SNAPSHOT:test" + \
            " | " + "grep __for__getty__\ __junit"
        output_raw = subprocess.check_output(mvn_cmd, shell=True).strip()
        start_index = output_raw.index("__for__getty__ __junit")
        if start_index == -1:
            raise
        elif start_index == 0:
            print "\nNormal customized surefire output starting at index 0"
            output = output_raw.split("\n")
        elif start_index == 10:
            print "\nCustomized surefire output starting at index 10, possibly with WARNING:"
            print output_raw
            output = output_raw[start_index:].split("\n")
        elif start_index > 10:
            print "\nCustomized surefire output starting at an abnormal index: " + str(start_index)
            print output_raw
            output = output_raw[start_index:].split("\n")
        else:
            raise
        merged_run = {}
        for junit_torun in output:
            junit_torun = junit_torun.strip()
            # vsn = junit_torun[17:23]
            to_run_list = junit_torun[26:].split(" ")
            runner = to_run_list[0]
            test_classes = set(to_run_list[1:])
            if runner in merged_run:
                merged_run[runner] = (test_classes | merged_run[runner])
            else:
                merged_run[runner] = test_classes
        if len(merged_run) < 1:
            raise NotImplementedError("this project is not using junit")
        elif len(merged_run) == 1:
            junit_runner = merged_run.keys()[0]
            return " ".join([junit_runner] + list(merged_run[junit_runner]))
        else:
            raise NotImplementedError("multiple junit versions are used in this project")
Пример #4
0
def _import_js(html_string, fe_path, go):
    import_script = "<script type=\"text/javascript\" src=\"{0}\"></script>"
    last_import = []
    for cssfile in [
            "styles.css", "styles_inv.css", "styles_src.css",
            "jquery-ui-1.12.1.min.css"
    ]:
        from_sys_call_enforce(" ".join(["cp", fe_path + cssfile,
                                        go + cssfile]))
    for jslib in [
            "jquery-3.1.1.min.js", "jquery-ui-1.12.1.min.js",
            "jquery.simpletip-1.3.2.js", "buckets.min.js", "run_prettify.js",
            "getty.js"
    ]:
        from_sys_call_enforce(" ".join(["cp", fe_path + jslib, go + jslib]))
        last_import.append(
            import_script.format(jslib + "?ver=" + config.version_time))
    last_import.append("</body>")
    last_import_str = "\n".join(last_import)
    return html_string.replace("</body>", last_import_str)
def is_different(target, go, prev_hash, post_hash):
    tfs = fsformat_with_sigs(target)
    prev_invs_file = go + "_getty_inv__" + tfs + "__" + prev_hash + "_.inv.out"
    post_invs_file = go + "_getty_inv__" + tfs + "__" + post_hash + "_.inv.out"
    if (not os.path.exists(prev_invs_file)) or (
            not os.path.exists(post_invs_file)):
        return True
    difftext = from_sys_call_enforce(" ".join(
        ["git diff", prev_invs_file, post_invs_file]))
    if difftext == "":
        return False
    else:
        return True
Пример #6
0
def __generate_append_diff(target, diff_type, prev_invf, post_invf,
                           diff_htmlf):
    global cached_header
    global caching_stage
    if diff_type not in ["ni", "ti4o", "ti4n", "si"]:
        raise ValueError(
            "diff_type must be one of 'ni', 'ti4o', 'ti4n', and 'si'")
    if config.use_tmp_files:
        prev_invs_file_tagged = __prediff_process(prev_invf, PRSV_LEFT,
                                                  PRSV_TMP)
        curr_invs_file_tagged = __prediff_process(post_invf, PRSV_RIGHT,
                                                  PRSV_TMP)
        dstring = from_sys_call_enforce(" ".join([
            "git diff", "--unified=" + str(config.inv_diff_context_lines),
            prev_invs_file_tagged, curr_invs_file_tagged
        ]))
    else:
        prev_invs_tagged = __prediff_process_in_memory(prev_invf, PRSV_LEFT)
        curr_invs_tagged = __prediff_process_in_memory(post_invf, PRSV_RIGHT)
        dstring = "diff --git a/invariants b/invariants\n"
        for ln in difflib.unified_diff(prev_invs_tagged,
                                       curr_invs_tagged,
                                       n=config.inv_diff_context_lines):
            dstring += ln

    cached_header = None
    caching_stage = False
    if len(dstring.split("\n")) <= config.max_diff_lines:
        dstring = __denoise(dstring)
        dtable = parse_from_memory(dstring, True, None, with_ln=False)
    else:
        print '   --- too big diff to be shown'
        dtable = '<div>The differential is too big to be shown</div>'

    inv_title = \
        "<div class='inv-cmp-title'><span class='menu-words'>Compare Invariants for</span> " + \
        "{ <span class='program-words'><b>" + __escape(target) + "</b></span> }</div>"
    invdiffhtml = \
        "<div id='vsinvs-" + diff_type + "-" + fsformat_with_sigs(target) + "'>" + \
        inv_title + "\n" + \
        ("NO DIFFERENCE" if is_empty(dtable) else dtable) + \
        "\n</div>\n"
    with open(diff_htmlf, 'w') as idout:
        idout.write(invdiffhtml)
    return invdiffhtml
def is_possibly_different(target, go, prev_hash, post_hash, preprocessed=False):
    if preprocessed:
        return __possible_diff_with_preprocessed_diff_html(target, go)
    else:
        tfs = fsformat(target)
        osot_invf = go + "_getty_inv__" + tfs + "__" + prev_hash + "_.inv.out"
        nsnt_invf = go + "_getty_inv__" + tfs + "__" + post_hash + "_.inv.out"
        osnt_invf = go + "_getty_inv__" + tfs + "__" + prev_hash + "_" + post_hash + "_.inv.out"
        nsot_invf = go + "_getty_inv__" + tfs + "__" + post_hash + "_" + prev_hash + "_.inv.out"
        all_pairs = [(osot_invf, nsnt_invf), (osnt_invf, nsnt_invf),
                     (osot_invf, osnt_invf), (nsot_invf, nsnt_invf)]
        for fpair in all_pairs:
            if (not os.path.exists(fpair[0])) or (not os.path.exists(fpair[1])):
                return True
            difftext = from_sys_call_enforce(" ".join(["git diff", fpair[0], fpair[1]]))
            if difftext != "":
                return True
        return False
Пример #8
0
def __generate_append_diff(target, diff_type, prev_invf, post_invf, diff_htmlf):
    global cached_header
    global caching_stage
    if diff_type not in ["ni", "ti4o", "ti4n", "si"]:
        raise ValueError("diff_type must be one of 'ni', 'ti4o', 'ti4n', and 'si'")
    if config.use_tmp_files:
        prev_invs_file_tagged = __prediff_process(prev_invf, PRSV_LEFT, PRSV_TMP)
        curr_invs_file_tagged = __prediff_process(post_invf, PRSV_RIGHT, PRSV_TMP)
        dstring = from_sys_call_enforce(
            " ".join(["git diff --unified=0", prev_invs_file_tagged, curr_invs_file_tagged]))
    else:
        prev_invs_tagged = __prediff_process_in_memory(prev_invf, PRSV_LEFT)
        curr_invs_tagged = __prediff_process_in_memory(post_invf, PRSV_RIGHT)
        dstring = "diff --git a/invariants b/invariants\n"
        for ln in difflib.unified_diff(prev_invs_tagged, curr_invs_tagged, n=0):
            dstring += ln

    cached_header = None
    caching_stage = False
    if len(dstring.split("\n")) <= config.max_diff_lines:
        dstring = __denoise(dstring)
        dtable = parse_from_memory(dstring, True, None, with_ln=False)
    else:
        print '   --- too big diff to be shown'
        dtable = '<div>The differential is too big to be shown</div>'
    
    inv_title = \
        "<div class='inv-cmp-title'><span class='menu-words'>Compare Invariants for</span> " + \
        "{ <span class='program-words'><b>" + __escape(target) + "</b></span> }</div>"
    invdiffhtml = \
        "<div id='vsinvs-" + diff_type + "-" + fsformat(target) + "'>" + \
        inv_title + "\n" + \
        ("NO DIFFERENCE" if is_empty(dtable) else dtable) + \
        "\n</div>\n"
    with open(diff_htmlf, 'w') as idout:
        idout.write(invdiffhtml)
    return invdiffhtml
def is_possibly_different(target,
                          go,
                          prev_hash,
                          post_hash,
                          preprocessed=False):
    if preprocessed:
        return __possible_diff_with_preprocessed_diff_html(target, go)
    else:
        tfs = fsformat_with_sigs(target)
        osot_invf = go + "_getty_inv__" + tfs + "__" + prev_hash + "_.inv.out"
        nsnt_invf = go + "_getty_inv__" + tfs + "__" + post_hash + "_.inv.out"
        osnt_invf = go + "_getty_inv__" + tfs + "__" + prev_hash + "_" + post_hash + "_.inv.out"
        nsot_invf = go + "_getty_inv__" + tfs + "__" + post_hash + "_" + prev_hash + "_.inv.out"
        all_pairs = [(osot_invf, nsnt_invf), (osnt_invf, nsnt_invf),
                     (osot_invf, osnt_invf), (nsot_invf, nsnt_invf)]
        for fpair in all_pairs:
            if (not os.path.exists(fpair[0])) or (not os.path.exists(
                    fpair[1])):
                return True
            difftext = from_sys_call_enforce(" ".join(
                ["git diff", fpair[0], fpair[1]]))
            if difftext != "":
                return True
        return False