mirror of https://github.com/astral-sh/ruff
fuzz-parser: catch exceptions from `pysource-minimize` (#14586)
This commit is contained in:
parent
66abef433b
commit
fab1b0d546
|
|
@ -20,6 +20,7 @@ Example invocations of the script:
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import ast
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import enum
|
import enum
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
@ -30,6 +31,7 @@ from pathlib import Path
|
||||||
from typing import NewType, assert_never
|
from typing import NewType, assert_never
|
||||||
|
|
||||||
from pysource_codegen import generate as generate_random_code
|
from pysource_codegen import generate as generate_random_code
|
||||||
|
from pysource_minimize import CouldNotMinimize
|
||||||
from pysource_minimize import minimize as minimize_repro
|
from pysource_minimize import minimize as minimize_repro
|
||||||
from rich_argparse import RawDescriptionRichHelpFormatter
|
from rich_argparse import RawDescriptionRichHelpFormatter
|
||||||
from termcolor import colored
|
from termcolor import colored
|
||||||
|
|
@ -150,7 +152,19 @@ def fuzz_code(seed: Seed, args: ResolvedCliArgs) -> FuzzResult:
|
||||||
executable=args.executable,
|
executable=args.executable,
|
||||||
executable_path=args.test_executable_path,
|
executable_path=args.test_executable_path,
|
||||||
)
|
)
|
||||||
maybe_bug = MinimizedSourceCode(minimize_repro(code, callback))
|
try:
|
||||||
|
maybe_bug = MinimizedSourceCode(minimize_repro(code, callback))
|
||||||
|
except CouldNotMinimize as e:
|
||||||
|
# This is to double-check that there isn't a bug in
|
||||||
|
# `pysource-minimize`/`pysource-codegen`.
|
||||||
|
# `pysource-minimize` *should* never produce code that's invalid syntax.
|
||||||
|
try:
|
||||||
|
ast.parse(code)
|
||||||
|
except SyntaxError:
|
||||||
|
raise e from None
|
||||||
|
else:
|
||||||
|
maybe_bug = MinimizedSourceCode(code)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
maybe_bug = None
|
maybe_bug = None
|
||||||
return FuzzResult(seed, maybe_bug, args.executable)
|
return FuzzResult(seed, maybe_bug, args.executable)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue