-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect illegal constructs used #10
Comments
I can think of 2 ways of approaching this atm. 1. Expose ast through ModuleContainerWithin the test, we can then write assertions that scan the ast for certain constructs. Macropy and quasiquotes make this simple enough. This might not be robust enough. (e.g. three ways of accessing and importing function sin from some module). There are ways to sneak past this, e.g. 2. Manipulate imports and builtinsThis would mean removing some functions from Patching the import system has a (serious?) drawback:
This would be sensible if we could somehow discover where a function is being called from - if it's from the tested file, raise an exception. |
As the module has evolved, I think the correct thing to do is to make decorator (implemented as a pre-test hook( that exposes the AST of the users program as a parameter to the tester function. @test
@expose_ast
def AST_test(m, AST):
# test ast inside This could be then extended with functions and wrappers that check the AST by walking through it. |
As of 81e597f, the syntax for exposing the AST works exactly as the above comment said. However, as there are no examples of walking the AST looking for nodes yet, I'm leaving this issue open. |
Some things that need to be supported: Given ast, find something that matches template. That could be a function, a while statement or whatever. Not sure if this would work everywhere, as it depends on the ast definition. |
Some tasks require that certain constructs are "banned" (e.g. "write your own max function"). We should expose an api for dealing with this.
This should be separate from #3, since this cannot be 100% foolproof, so it shouldn't be used to block some sys calls etc.
The text was updated successfully, but these errors were encountered: