コード例 #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_infinite_actual_lines_due_to_infinite_loop(self) -> None:
        exp_seq = ("a\n", "b\n")
        act_seq = ["a\n", "b\n"]
        self.assertNotEqual(exp_seq, act_seq)

        # unlike __eq__ (operator ==), equal_lines returns True
        self.assertTrue(diff.equal_lines(iter(exp_seq), iter(act_seq)))
コード例 #3
0
    def test_equal_lines_same_len(self) -> None:
        exp = """\
#starts here
.main {
  Int 1
  RetC
}
#ends here
        """
        act = """\
#starts here
.main {
  Int 2
  RetC
}
#ends here
        """
        self.assertFalse(diff.equal_lines(iter_lines(exp), iter_lines(act)))
        self.assertTrue(
            diff.equal_lines(iter_lines(exp), iter_lines(act.replace("2",
                                                                     "1"))))
コード例 #4
0
    def test_infinite_actual_lines_due_to_infinite_loop(self) -> None:
        COMMON_LINE = "foo\n"

        def gen_foo_once() -> Iterator[str]:
            yield COMMON_LINE

        def gen_foo_indefinitely() -> Iterator[str]:
            while True:
                yield COMMON_LINE

        self.assertFalse(
            diff.equal_lines(gen_foo_once(), gen_foo_indefinitely()))
コード例 #5
0
    def test_infinite_actual_lines_due_to_infinite_loop(self) -> None:
        COMMON_LINE = "foo\n"

        # pyre-fixme[53]: Captured variable `COMMON_LINE` is not annotated.
        def gen_foo_once() -> Iterator[str]:
            yield COMMON_LINE

        # pyre-fixme[53]: Captured variable `COMMON_LINE` is not annotated.
        def gen_foo_indefinitely() -> Iterator[str]:
            while True:
                yield COMMON_LINE

        self.assertFalse(
            diff.equal_lines(gen_foo_once(), gen_foo_indefinitely()))
コード例 #6
0
ファイル: hh_asdiff.py プロジェクト: zawkhantmg/hhvm
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)
コード例 #7
0
ファイル: hh_asdiff.py プロジェクト: zawkhantmg/hhvm
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