Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Oct 1, 2023
1 parent e7c3368 commit de8e160
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions scripts/find_issue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@


import ast
from pathlib import Path

from pysource_codegen import generate
from pysource_minimize import minimize

import black
from blib2to3.pgen2.literals import test

base_path=Path(__file__).parent

def bug_in_code(src_contents,mode):

try:
dst_contents = black.format_str(src_contents, mode=mode)

black.assert_equivalent(src_contents, dst_contents)
black.assert_stable(src_contents, dst_contents, mode=mode)
except Exception as e:
print("error:",e)
return True
return False


def find_issue() -> None:

for seed in range(38,100000):
#for seed in [4414]:
src_contents=generate(seed)
print("seed:",seed)

compile(src_contents, "<string>", "exec")

mode=black.FileMode(
line_length=80,
string_normalization=True,
is_pyi=False,
magic_trailing_comma=False,
)

if bug_in_code(src_contents,mode):
new_code=ast.unparse(ast.parse(src_contents,type_comments=True))
(base_path/"new_code.py").write_text(new_code)
(base_path/"src_code.py").write_text(src_contents)
for a,b in zip(new_code.splitlines(),src_contents.splitlines()):
if a!=b:
print("mismatch")
print(a)
print(b)

assert bug_in_code(src_contents,mode)
assert bug_in_code(new_code,mode)

minimized=minimize(src_contents,lambda code:bug_in_code(code,mode))

print("seed:",seed)
print("minimized code:")
print(minimized)
assert bug_in_code(minimized,mode)
(base_path/"min_code.py").write_text(minimized)

if "match" not in minimized:
return

#if "with" not in minimized:
# return




if __name__ == "__main__":
find_issue()

0 comments on commit de8e160

Please sign in to comment.