4 hours ago · Tech · hide · 0 comments

I’ve had an idea rattling around to get more detail from coverage measurement. Can we measure the coverage in a function separately for each caller of the function?Here’s why I want it: in Acidica, my toy BASIC interpreter, I have code to implement the built-in functions that looks something like this:match func_name: case "LEN": if len(args) != 1: raise TypeError(f"Wrong arguments for LEN, got {len(args)}") return len(args[0]) case "LEFT$": if len(args) != 2: raise TypeError(f"Wrong arguments for LEFT$, got {len(args)}") return args[0][:args[1]] # ... 19 other built-ins ... I didn’t like the repeated code here: each different func_name has to check that it got its expected number of arguments and perhaps raise an error. So I refactored:def expects(nargs: int, func_name: str, args: tuple) -> None: if len(args) != nargs: raise TypeError(f"Wrong arguments for {func_name}, got {len(args)}") match func_name: case "LEN": expects(1, func_name, args) return len(args[0]) case "LEFT$":…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.