-
Notifications
You must be signed in to change notification settings - Fork 162
feat: implement no_stdlib option #1104
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ recordkey | |
| retlist | ||
| retstat | ||
| setmetatable | ||
| stdlib | ||
| subtyping | ||
| tableconstructor | ||
| tlconfig | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| local assert = require("luassert") | ||
| local util = require("spec.util") | ||
|
|
||
| describe("--no-stdlib argument", function() | ||
| it("prevent the Lua stdlib to be used", function() | ||
| util.do_in(util.write_tmp_dir(finally, { | ||
| ["test.tl"] = [[ | ||
| print("hello world") | ||
| ]], | ||
| }), function() | ||
| local pd = io.popen(util.tl_cmd("check", "--no-stdlib", "test.tl") .. " 2>&1 1>" .. util.os_null, "r") | ||
| local output = pd:read("*a") | ||
| util.assert_popen_close(1, pd:close()) | ||
| assert.match("1 error:", output, 1, true) | ||
| end) | ||
| end) | ||
| it("reads no_std from tlconfig.lua", function() | ||
| util.do_in(util.write_tmp_dir(finally, { | ||
| ["test.tl"] = [[ | ||
| print("hello world") | ||
| ]], | ||
| ["tlconfig.lua"] = [[ | ||
| return { | ||
| no_stdlib = true, | ||
| } | ||
| ]], | ||
| }), function() | ||
| local pd = io.popen(util.tl_cmd("check", "test.tl") .. " 2>&1 1>" .. util.os_null, "r") | ||
| local output = pd:read("*a") | ||
| util.assert_popen_close(1, pd:close()) | ||
| assert.match("1 error:", output, 1, true) | ||
| end) | ||
| end) | ||
| end) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ local record environment | |
| gen_compat: GenCompat | ||
| gen_target: GenTarget | ||
| run_internal_compiler_checks: boolean | ||
| no_stdlib: boolean | ||
| end | ||
|
|
||
| type RequireModuleFn = function(env: Env, module_name: string): Type, string | ||
|
|
@@ -140,7 +141,9 @@ end | |
| function environment.new(opts?: EnvOptions): Env | ||
| local env = empty_environment() | ||
| env.opts = opts or env.opts | ||
| load_precompiled_default_env(env) | ||
| if not env.opts.no_stdlib then | ||
| load_precompiled_default_env(env) | ||
| end | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add an I believe
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added with a basic |
||
| return env | ||
| end | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a line to
test.tlhere with a simple use of a fundamental prelude type, like:We should still only get 1 error from the missing
printfunction.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's indeed a good addition. However, the tests are still green when with prelude words, reporting no more than the initial 1 error for
print. To me, it seems like the prelude works, even without the recommendedenv:require_module("teal.default.prelude").There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, good catch. I don't have it off the top of my head, but maybe
anygets special cased when parsing. But I think the default metamethods from the prelude will probably trigger an error if those are missing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes,
metatablethings fail without the prelude. I have added a newitin the suite to test prelude specifics types.