def check(args: argparse.Namespace, options: AnalysisOptionSet, stdout: TextIO, stderr: TextIO) -> int: any_problems = False try: entities = list(load_files_or_qualnames(args.target)) except FileNotFoundError as exc: print(f'File not found: "{exc.args[0]}"', file=stderr) return 2 except ErrorDuringImport as exc: cause = exc.__cause__ if exc.__cause__ is not None else exc print(f"Could not import your code:\n", file=stderr) traceback.print_exception(type(cause), cause, cause.__traceback__, file=stderr) return 2 full_options = DEFAULT_OPTIONS.overlay( report_verbose=False).overlay(options) for entity in entities: debug("Check ", getattr(entity, "__name__", str(entity))) for message in run_checkables(analyze_any(entity, options)): line = describe_message(message, full_options) if line is None: continue stdout.write(line + "\n") debug("Traceback for output message:\n", message.traceback) if message.state > MessageType.PRE_UNSAT: any_problems = True return 1 if any_problems else 0
def test_builtin(fn_name: str) -> None: opts = AnalysisOptionSet( max_iterations=20, per_condition_timeout=20, per_path_timeout=5 ) this_module = sys.modules[__name__] fn = getattr(this_module, fn_name) messages = run_checkables(analyze_function(fn, opts)) errors = [m for m in messages if m.state > MessageType.PRE_UNSAT] assert errors == []
def pool_worker_process_item( item: WorkItemInput, ) -> Tuple[Counter[str], List[AnalysisMessage]]: filename, options, deadline = item stats: Counter[str] = Counter() options.stats = stats try: module = load_file(filename) except NotFound as e: debug( f'Not analyzing "{filename}" because sub-module import failed: {e}' ) return (stats, []) except ErrorDuringImport as e: debug(f'Not analyzing "{filename}" because import failed: {e}') return (stats, [import_error_msg(e)]) messages = run_checkables(analyze_module(module, options)) return (stats, messages)
def test_builtins() -> None: opts = AnalysisOptionSet(max_iterations=5, per_condition_timeout=10) messages = run_checkables(analyze_module(sys.modules[__name__], opts)) errors = [m for m in messages if m.state > MessageType.PRE_UNSAT] assert errors == []