2024-05-13 15:37:53 +02:00
|
|
|
use crate::repl::tests::{fail_test, run_test, TestResult};
|
2021-12-25 20:39:42 +01:00
|
|
|
|
|
|
|
// TODO: Test the use/hide tests also as separate lines in REPL (i.e., with merging the delta in between)
|
|
|
|
#[test]
|
|
|
|
fn hides_def() -> TestResult {
|
2023-03-11 19:01:24 +01:00
|
|
|
fail_test(
|
|
|
|
r#"def myfoosymbol [] { "myfoosymbol" }; hide myfoosymbol; myfoosymbol"#,
|
|
|
|
"external_command",
|
|
|
|
)
|
2021-12-25 20:39:42 +01:00
|
|
|
}
|
|
|
|
|
2022-02-12 10:50:37 +01:00
|
|
|
#[test]
|
|
|
|
fn hides_alias() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"alias myfoosymbol = echo "myfoosymbol"; hide myfoosymbol; myfoosymbol"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2022-02-12 10:50:37 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-25 20:39:42 +01:00
|
|
|
#[test]
|
|
|
|
fn hides_env() -> TestResult {
|
2023-03-11 19:01:24 +01:00
|
|
|
fail_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"$env.myfoosymbol = "myfoosymbol"; hide-env myfoosymbol; $env.myfoosymbol"#,
|
2023-03-11 19:01:24 +01:00
|
|
|
"",
|
|
|
|
)
|
2021-12-25 20:39:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_def_then_redefines() -> TestResult {
|
|
|
|
// this one should fail because of predecl -- cannot have more defs with the same name in a
|
|
|
|
// block
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"def myfoosymbol [] { "myfoosymbol" }; hide myfoosymbol; def myfoosymbol [] { "bar" }; myfoosymbol"#,
|
2021-12-25 20:39:42 +01:00
|
|
|
"defined more than once",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
Re-implement aliases (#8123)
# Description
This PR adds an alternative alias implementation. Old aliases still work
but you need to use `old-alias` instead of `alias`.
Instead of replacing spans in the original code and re-parsing, which
proved to be extremely error-prone and a constant source of panics, the
new implementation creates a new command that references the old
command. Consider the new alias defined as `alias ll = ls -l`. The
parser creates a new command called `ll` and remembers that it is
actually a `ls` command called with the `-l` flag. Then, when the parser
sees the `ll` command, it will translate it to `ls -l` and passes to it
any parameters that were passed to the call to `ll`. It works quite
similar to how known externals defined with `extern` are implemented.
The new alias implementation should work the same way as the old
aliases, including exporting from modules, referencing both known and
unknown externals. It seems to preserve custom completions and pipeline
metadata. It is quite robust in most cases but there are some rough
edges (see later).
Fixes https://github.com/nushell/nushell/issues/7648,
https://github.com/nushell/nushell/issues/8026,
https://github.com/nushell/nushell/issues/7512,
https://github.com/nushell/nushell/issues/5780,
https://github.com/nushell/nushell/issues/7754
No effect: https://github.com/nushell/nushell/issues/8122 (we might
revisit the completions code after this PR)
Should use custom command instead:
https://github.com/nushell/nushell/issues/6048
# User-Facing Changes
Since aliases are now basically commands, it has some new implications:
1. `alias spam = "spam"` (requires command call)
* **workaround**: use `alias spam = echo "spam"`
2. `def foo [] { 'foo' }; alias foo = ls -l` (foo defined more than
once)
* **workaround**: use different name (commands also have this
limitation)
4. `alias ls = (ls | sort-by type name -i)`
* **workaround**: Use custom command. _The common issue with this is
that it is currently not easy to pass flags through custom commands and
command referencing itself will lead to stack overflow. Both of these
issues are meant to be addressed._
5. TODO: Help messages, `which` command, `$nu.scope.aliases`, etc.
* Should we treat the aliases as commands or should they be separated
from regular commands?
6. Needs better error message and syntax highlight for recursed alias
(`alias f = f`)
7. Can't create alias with the same name as existing command (`alias ls
= ls -a`)
* Might be possible to add support for it (not 100% sure)
8. Standalone `alias` doesn't list aliases anymore
9. Can't alias parser keywords (e.g., stuff like `alias ou = overlay
use` won't work)
* TODO: Needs a better error message when attempting to do so
# Tests + Formatting
Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
# After Submitting
If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-27 08:44:05 +01:00
|
|
|
#[ignore = "TODO: We'd need to make predecls work with hiding as well"]
|
2022-02-12 10:50:37 +01:00
|
|
|
#[test]
|
|
|
|
fn hides_alias_then_redefines() -> TestResult {
|
|
|
|
run_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"alias myfoosymbol = echo "myfoosymbol"; hide myfoosymbol; alias myfoosymbol = echo "myfoosymbol"; myfoosymbol"#,
|
|
|
|
"myfoosymbol",
|
2022-02-12 10:50:37 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-25 20:39:42 +01:00
|
|
|
#[test]
|
|
|
|
fn hides_env_then_redefines() -> TestResult {
|
|
|
|
run_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"$env.myfoosymbol = "myfoosymbol"; hide-env myfoosymbol; $env.myfoosymbol = "bar"; $env.myfoosymbol"#,
|
2021-12-25 20:39:42 +01:00
|
|
|
"bar",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_def_in_scope_1() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"def myfoosymbol [] { "myfoosymbol" }; do { hide myfoosymbol; myfoosymbol }"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_def_in_scope_2() -> TestResult {
|
|
|
|
run_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"def myfoosymbol [] { "myfoosymbol" }; do { def myfoosymbol [] { "bar" }; hide myfoosymbol; myfoosymbol }"#,
|
|
|
|
"myfoosymbol",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_def_in_scope_3() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"def myfoosymbol [] { "myfoosymbol" }; do { hide myfoosymbol; def myfoosymbol [] { "bar" }; hide myfoosymbol; myfoosymbol }"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_def_in_scope_4() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"def myfoosymbol [] { "myfoosymbol" }; do { def myfoosymbol [] { "bar" }; hide myfoosymbol; hide myfoosymbol; myfoosymbol }"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-12 10:50:37 +01:00
|
|
|
#[test]
|
|
|
|
fn hides_alias_in_scope_1() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"alias myfoosymbol = echo "myfoosymbol"; do { hide myfoosymbol; myfoosymbol }"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2022-02-12 10:50:37 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_alias_in_scope_2() -> TestResult {
|
|
|
|
run_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"alias myfoosymbol = echo "myfoosymbol"; do { alias myfoosymbol = echo "bar"; hide myfoosymbol; myfoosymbol }"#,
|
|
|
|
"myfoosymbol",
|
2022-02-12 10:50:37 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_alias_in_scope_3() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"alias myfoosymbol = echo "myfoosymbol"; do { hide myfoosymbol; alias myfoosymbol = echo "bar"; hide myfoosymbol; myfoosymbol }"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2022-02-12 10:50:37 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_alias_in_scope_4() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"alias myfoosymbol = echo "myfoosymbol"; do { alias myfoosymbol = echo "bar"; hide myfoosymbol; hide myfoosymbol; myfoosymbol }"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2022-02-12 10:50:37 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-25 20:39:42 +01:00
|
|
|
#[test]
|
|
|
|
fn hides_env_in_scope_1() -> TestResult {
|
2022-09-25 18:52:43 +02:00
|
|
|
fail_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"$env.myfoosymbol = "myfoosymbol"; do { hide-env myfoosymbol; $env.myfoosymbol }"#,
|
2022-12-10 18:23:34 +01:00
|
|
|
"not_found",
|
2022-09-25 18:52:43 +02:00
|
|
|
)
|
2021-12-25 20:39:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_env_in_scope_2() -> TestResult {
|
|
|
|
run_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"$env.myfoosymbol = "myfoosymbol"; do { $env.myfoosymbol = "bar"; hide-env myfoosymbol; $env.myfoosymbol }"#,
|
2023-03-11 19:01:24 +01:00
|
|
|
"myfoosymbol",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_env_in_scope_3() -> TestResult {
|
|
|
|
fail_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"$env.myfoosymbol = "myfoosymbol"; do { hide-env myfoosymbol; $env.myfoosymbol = "bar"; hide-env myfoosymbol; $env.myfoosymbol }"#,
|
2022-09-21 02:46:01 +02:00
|
|
|
"",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_env_in_scope_4() -> TestResult {
|
|
|
|
fail_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"$env.myfoosymbol = "myfoosymbol"; do { $env.myfoosymbol = "bar"; hide-env myfoosymbol; hide-env myfoosymbol; $env.myfoosymbol }"#,
|
2022-09-21 02:46:01 +02:00
|
|
|
"",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-17 23:35:50 +01:00
|
|
|
#[ignore]
|
2021-12-25 20:39:42 +01:00
|
|
|
fn hide_def_twice_not_allowed() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"def myfoosymbol [] { "myfoosymbol" }; hide myfoosymbol; hide myfoosymbol"#,
|
2021-12-25 20:39:42 +01:00
|
|
|
"did not find",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-12 10:50:37 +01:00
|
|
|
#[test]
|
2022-03-17 23:35:50 +01:00
|
|
|
#[ignore]
|
2022-02-12 10:50:37 +01:00
|
|
|
fn hide_alias_twice_not_allowed() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"alias myfoosymbol = echo "myfoosymbol"; hide myfoosymbol; hide myfoosymbol"#,
|
2022-02-12 10:50:37 +01:00
|
|
|
"did not find",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-25 20:39:42 +01:00
|
|
|
#[test]
|
|
|
|
fn hide_env_twice_not_allowed() -> TestResult {
|
2023-03-11 19:01:24 +01:00
|
|
|
fail_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"$env.myfoosymbol = "myfoosymbol"; hide-env myfoosymbol; hide-env myfoosymbol"#,
|
2023-03-11 19:01:24 +01:00
|
|
|
"",
|
|
|
|
)
|
2022-08-13 11:55:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hide_env_twice_allowed() -> TestResult {
|
|
|
|
fail_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"$env.myfoosymbol = "myfoosymbol"; hide-env myfoosymbol; hide-env -i myfoosymbol; $env.myfoosymbol"#,
|
2022-09-21 02:46:01 +02:00
|
|
|
"",
|
2022-08-13 11:55:06 +02:00
|
|
|
)
|
2021-12-25 20:39:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-02-12 18:48:51 +01:00
|
|
|
fn hides_def_runs_env() -> TestResult {
|
2021-12-25 20:39:42 +01:00
|
|
|
run_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"$env.myfoosymbol = "bar"; def myfoosymbol [] { "myfoosymbol" }; hide myfoosymbol; $env.myfoosymbol"#,
|
2021-12-25 20:39:42 +01:00
|
|
|
"bar",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_def_import_1() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export def myfoosymbol [] { "myfoosymbol" } }; use myspammodule; hide myspammodule myfoosymbol; myspammodule myfoosymbol"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_def_import_2() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export def myfoosymbol [] { "myfoosymbol" } }; use myspammodule; hide myspammodule; myspammodule myfoosymbol"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_def_import_3() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export def myfoosymbol [] { "myfoosymbol" } }; use myspammodule; hide myspammodule [myfoosymbol]; myspammodule myfoosymbol"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_def_import_4() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export def myfoosymbol [] { "myfoosymbol" } }; use myspammodule myfoosymbol; hide myfoosymbol; myfoosymbol"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_def_import_5() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export def myfoosymbol [] { "myfoosymbol" } }; use myspammodule *; hide myfoosymbol; myfoosymbol"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_def_import_6() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export def myfoosymbol [] { "myfoosymbol" } }; use myspammodule *; hide myspammodule *; myfoosymbol"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-25 23:56:40 +01:00
|
|
|
#[test]
|
|
|
|
fn hides_def_import_then_reimports() -> TestResult {
|
|
|
|
run_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export def myfoosymbol [] { "myfoosymbol" } }; use myspammodule myfoosymbol; hide myfoosymbol; use myspammodule myfoosymbol; myfoosymbol"#,
|
|
|
|
"myfoosymbol",
|
2022-03-25 23:56:40 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_alias_import_1() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export alias myfoosymbol = echo "myfoosymbol" }; use myspammodule; hide myspammodule myfoosymbol; myspammodule myfoosymbol"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2022-03-25 23:56:40 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_alias_import_2() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export alias myfoosymbol = echo "myfoosymbol" }; use myspammodule; hide myspammodule; myspammodule myfoosymbol"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2022-03-25 23:56:40 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_alias_import_3() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export alias myfoosymbol = echo "myfoosymbol" }; use myspammodule; hide myspammodule [myfoosymbol]; myspammodule myfoosymbol"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2022-03-25 23:56:40 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_alias_import_4() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export alias myfoosymbol = echo "myfoosymbol" }; use myspammodule myfoosymbol; hide myfoosymbol; myfoosymbol"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2022-03-25 23:56:40 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_alias_import_5() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export alias myfoosymbol = echo "myfoosymbol" }; use myspammodule *; hide myfoosymbol; myfoosymbol"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2022-03-25 23:56:40 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_alias_import_6() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export alias myfoosymbol = echo "myfoosymbol" }; use myspammodule *; hide myspammodule *; myfoosymbol"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2022-03-25 23:56:40 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_alias_import_then_reimports() -> TestResult {
|
|
|
|
run_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export alias myfoosymbol = echo "myfoosymbol" }; use myspammodule myfoosymbol; hide myfoosymbol; use myspammodule myfoosymbol; myfoosymbol"#,
|
|
|
|
"myfoosymbol",
|
2022-03-25 23:56:40 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-25 20:39:42 +01:00
|
|
|
#[test]
|
|
|
|
fn hides_env_import_1() -> TestResult {
|
|
|
|
fail_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"module myspammodule { export-env { $env.myfoosymbol = "myfoosymbol" } }; use myspammodule; hide-env myfoosymbol; $env.myfoosymbol"#,
|
2022-09-21 02:46:01 +02:00
|
|
|
"",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_def_runs_env_import() -> TestResult {
|
|
|
|
run_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"module myspammodule { export-env { $env.myfoosymbol = "myfoosymbol" }; export def myfoosymbol [] { "bar" } }; use myspammodule myfoosymbol; hide myfoosymbol; $env.myfoosymbol"#,
|
2023-03-11 19:01:24 +01:00
|
|
|
"myfoosymbol",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_def_and_env_import_1() -> TestResult {
|
|
|
|
fail_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"module myspammodule { export-env { $env.myfoosymbol = "myfoosymbol" }; export def myfoosymbol [] { "bar" } }; use myspammodule myfoosymbol; hide myfoosymbol; hide-env myfoosymbol; $env.myfoosymbol"#,
|
2022-09-21 02:46:01 +02:00
|
|
|
"",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn use_def_import_after_hide() -> TestResult {
|
|
|
|
run_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export def myfoosymbol [] { "myfoosymbol" } }; use myspammodule myfoosymbol; hide myfoosymbol; use myspammodule myfoosymbol; myfoosymbol"#,
|
|
|
|
"myfoosymbol",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn use_env_import_after_hide() -> TestResult {
|
|
|
|
run_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"module myspammodule { export-env { $env.myfoosymbol = "myfoosymbol" } }; use myspammodule; hide-env myfoosymbol; use myspammodule; $env.myfoosymbol"#,
|
2023-03-11 19:01:24 +01:00
|
|
|
"myfoosymbol",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hide_shadowed_decl() -> TestResult {
|
|
|
|
run_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export def myfoosymbol [] { "bar" } }; def myfoosymbol [] { "myfoosymbol" }; do { use myspammodule myfoosymbol; hide myfoosymbol; myfoosymbol }"#,
|
|
|
|
"myfoosymbol",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hide_shadowed_env() -> TestResult {
|
|
|
|
run_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"module myspammodule { export-env { $env.myfoosymbol = "bar" } }; $env.myfoosymbol = "myfoosymbol"; do { use myspammodule; hide-env myfoosymbol; $env.myfoosymbol }"#,
|
2023-03-11 19:01:24 +01:00
|
|
|
"myfoosymbol",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_all_decls_within_scope() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export def myfoosymbol [] { "bar" } }; def myfoosymbol [] { "myfoosymbol" }; use myspammodule myfoosymbol; hide myfoosymbol; myfoosymbol"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_all_envs_within_scope() -> TestResult {
|
|
|
|
fail_test(
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"module myspammodule { export-env { $env.myfoosymbol = "bar" } }; $env.myfoosymbol = "myfoosymbol"; use myspammodule; hide-env myfoosymbol; $env.myfoosymbol"#,
|
2022-09-21 02:46:01 +02:00
|
|
|
"",
|
2021-12-25 20:39:42 +01:00
|
|
|
)
|
|
|
|
}
|
2023-01-22 20:34:15 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_main_import_1() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export def main [] { "myfoosymbol" } }; use myspammodule; hide myspammodule; myspammodule"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_main_import_2() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export def main [] { "myfoosymbol" } }; use myspammodule; hide myspammodule main; myspammodule"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_main_import_3() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export def main [] { "myfoosymbol" } }; use myspammodule; hide myspammodule [ main ]; myspammodule"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hides_main_import_4() -> TestResult {
|
|
|
|
fail_test(
|
2023-03-11 19:01:24 +01:00
|
|
|
r#"module myspammodule { export def main [] { "myfoosymbol" } }; use myspammodule; hide myspammodule *; myspammodule"#,
|
2023-01-22 20:34:15 +01:00
|
|
|
"external_command",
|
|
|
|
)
|
|
|
|
}
|