Пример #1
0
def report_summary(exp_file: Iterator[AnyStr], act_file: Iterator[AnyStr]):
    act: Dict[Optional[str], Sequence[str]] = {}
    exp: Dict[Optional[str], Sequence[str]] = {}
    for fn, content in parsing.split_lines(exp_file):
        if fn is None:
            log.error("Found file without name")
        exp[fn] = content
    act = {}
    for fn, content in parsing.split_lines(act_file):
        if fn is None:
            log.error("Found file without name")
        act[fn] = content
    exp_keys = set(exp.keys())
    act_keys = set(act.keys())
    all_keys = sorted(exp_keys.union(act_keys))

    for k in all_keys:
        from_exp = exp.get(k)
        from_act = act.get(k)
        if from_exp is None:
            print("|NotInExp|", k)
        elif from_act is None:
            print("|NotInAct|", k)
        elif diff.equal_lines(iter(from_exp), iter(from_act)):
            print("|Identical|", k)
        else:
            print("|Mismatch|", k)
Пример #2
0
    def test_lines_no_markers_ignores_all(self) -> None:
        count = 0
        lines = ["1\n", "2\n", "3\n"]

        def count_ignored(_) -> None:
            nonlocal count
            count += 1

        list(parsing.split_lines(iter(lines),
                                 count_ignored))  # force evaluation
        self.assertEqual(count, len(lines))
Пример #3
0
    def test_lines_no_markers_ignores_all(self) -> None:
        count = 0
        lines = ["1\n", "2\n", "3\n"]

        # pyre-fixme[53]: Captured variable `count` is not annotated.
        def count_ignored(_) -> None:
            nonlocal count
            count += 1

        list(parsing.split_lines(iter(lines), count_ignored))  # force evaluation
        self.assertEqual(count, len(lines))
Пример #4
0
def report_summary(exp_file: Iterator[AnyStr], act_file: Iterator[AnyStr]):
    act: Dict[Optional[str], Sequence[str]] = {}
    exp: Dict[Optional[str], Sequence[str]] = {}
    for fn, content in parsing.split_lines(exp_file):
        if fn is None:
            log.error("Found file without name")
        exp[fn] = content
    act = {}
    for fn, content in parsing.split_lines(act_file):
        if fn is None:
            log.error("Found file without name")
        act[fn] = content
    exp_keys = set(exp.keys())
    act_keys = set(act.keys())
    # pyre-fixme[6]: Expected `Iterable[Variable[_LT (bound to _SupportsLessThan)]]`
    #  for 1st param but got `Set[Optional[str]]`.
    all_keys = sorted(exp_keys.union(act_keys))

    for k in all_keys:
        from_exp = exp.get(k)
        from_act = act.get(k)
        if from_exp is None:
            print("|NotInExp|", k)
        elif from_act is None:
            print("|NotInAct|", k)
        elif (
            next(filter(lambda l: "#### NotImpl:" in l, iter(from_act)), None)
            is not None
        ):
            print("|PrintNotImplA|", k)
        elif (
            next(filter(lambda l: "#### NotImpl:" in l, iter(from_exp)), None)
            is not None
        ):
            print("|PrintNotImplE|", k)
        elif diff.equal_lines(iter(from_exp), iter(from_act)):
            print("|Identical|", k)
        else:
            print("|Mismatch|", k)
Пример #5
0
    def test_split_multiple_files_with_filenames(self) -> None:
        line_iter = iter(
            parsing.split_lines(
                iter_lines("""\
# dir/file1.php starts here
HHAS1
# dir/file1.php ends here
# dir/file2.php starts here
HHAS2a
HHAS2b
# dir/file2.php ends here
""")))
        self.assertEqual(next(line_iter, None), ("dir/file1.php", ["HHAS1\n"]))
        self.assertEqual(next(line_iter, None),
                         ("dir/file2.php", ["HHAS2a\n", "HHAS2b\n"]))
Пример #6
0
    def test_lines_single_marker_pair_no_filename(self) -> None:
        lines = iter_lines("""\
GARBAGE1
#starts here
.main {
  Int 1
  RetC
}
#ends here
GARBAGE2
""")
        line_iter = iter(lines)
        ignored_lines = []
        gen = parsing.split_lines(line_iter,
                                  lambda ln: ignored_lines.append(ln))
        exp1 = (None, [".main {\n", "  Int 1\n", "  RetC\n", "}\n"])
        self.assertEqual(next(gen, None), exp1)
        self.assertIsNone(next(gen, None))
        self.assertEqual(ignored_lines, ["GARBAGE1\n", "GARBAGE2\n"])
Пример #7
0
def main(args: List[str]) -> int:
    exit_code = 0
    opts = parse_args(sys.argv)
    compare_all = opts.all or opts.diff_smallest
    try:
        if opts.report_summary:
            report_summary(opts.expected_file, opts.actual_file)
            return exit_code
        compare_count = 0
        diff_handler = DiffHandler(opts)
        for exp, act in itertools.zip_longest(
            parsing.split_lines(opts.expected_file),
            parsing.split_lines(opts.actual_file),
            fillvalue=None,
        ):
            compare_count += 1
            if None in (exp, act):
                exit_code |= 1 << 1
                source, filename = (
                    ("expected", act[0]) if exp is None else ("actual", exp[0])
                )
                log.error(f"missing filename in {source} HHAS: {filename}")
                if not compare_all:
                    break
                continue

            exp_filename, exp_lines = exp
            act_filename, act_lines = act
            if exp_filename != act_filename:
                exit_code |= 1 << 2
                log.error(
                    "filename mismatch:\n"
                    f"expected: {exp_filename}\n"
                    f"  actual: {act_filename}\n"
                    "Did you ensure stable order in `hh_(single_)compile "
                    "--input-file-list`?"
                )
                if not compare_all:
                    break
                continue

            if diff.equal_lines(exp_lines, act_lines):
                if opts.report_identical_files:
                    print("identical:", exp_filename)
                continue

            exit_code |= 1 << 3
            diff_handler(exp, act)

            if not compare_all:
                break

        print("files checked:", compare_count)
        print(str(diff_handler), end="")
        if opts.diff:
            for rank, ((_, exp_file), exp_lines, act_lines) in enumerate(
                diff_handler.ranker, start=1
            ):
                print(f"\n== Rank #{rank} diff:", exp_file)
                gen = difflib.unified_diff(exp_lines, act_lines)
                next(gen)  # skip: +++ file1
                next(gen)  # skip: --- file2
                sys.stdout.writelines(gen)
    finally:
        opts.expected_file.close()
        opts.actual_file.close()

    return exit_code