-
Notifications
You must be signed in to change notification settings - Fork 34
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
call() scope does not override imported symbols #116
Comments
Imported symbols act like local variables, that's why you can't shadow them by overriding the scope (once the compiled bytecode runs, accessing imported symbols is not a property lookup in the global scope but a direct stack slot / upvalue access, basically the same as a local variable). Without introducing a set of debug/introspection APIs, the only solution I can think of is compiling and loading the code to test at runtime using If that is not an option, then we will need a kind of debug library, comparable to the Lua one, which allows getting and setting the bound upvalues of a function in order to patch other values in there. |
If that is too complex, then I guess I'll have to improve my Typescript transformer (to make it transparent) or my test lib (to make it work also without TS) so that it loads functions to test not directly but thru a helper. This would then use |
Is it normal that I can't shadow defined constants as well? // lib.uc
const to_stub = () => "original"
function fn_to_test() {
return to_stub();
}
export { fn_to_test }; // lib.spec.uc
import { fn_to_test } from './lib.uc';
print(call(fn_to_test, { to_stub: () => "override" })); // prints "oiriginal" |
Yes, those are local variables too. |
Oh, I thought you meant local variables in the function scope, not in the global scope (ie the one holding the function). Now I understand 😄 |
@jow- as I mentioned before, I've just published the draft of my TypeScript to ucode compiler there - you get typings, classes and code completion for ucode thanks to typescript and some transformers. Plus the code is going thru eslint to ensure no |
I've wrote a Typescript transformer for
ucode
as well as typings so that one can writeucode
code with strict typings. I've also wrote a test library with spies and stubs so that ucode projects can have unit tests also written in Typescript. it's going to be on my public Github once ready (or at least when in a more advanced stage).For the spies and stubs, I'm using the
call
function which is pretty handy. Tho there is one blocking issue:here I was expecting
fn_to_test
to use the dummy() => null
when callingto_stub
instead of the one imported frommy_lib.uc
.I guess it's the normal behavior, tho it'd be nice if the scope given to
call()
could override imported symbols as well as globals.The text was updated successfully, but these errors were encountered: