2021-03-15 08:26:30 +01:00
|
|
|
use nu_test_support::fs::Stub::FileWithContent;
|
|
|
|
use nu_test_support::fs::{AbsolutePath, DisplayPath};
|
|
|
|
use nu_test_support::playground::{says, Playground};
|
|
|
|
|
|
|
|
use hamcrest2::assert_that;
|
|
|
|
use hamcrest2::prelude::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn config_path_variable_present() {
|
|
|
|
Playground::setup("nu_variable_test_1", |_, nu| {
|
|
|
|
assert_that!(
|
|
|
|
nu.pipeline("echo $nu.config-path"),
|
2021-06-17 21:59:58 +02:00
|
|
|
says().stdout(nu.get_config())
|
2021-03-15 08:26:30 +01:00
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn custom_config_path_variable_present() {
|
|
|
|
Playground::setup("nu_variable_test_2", |dirs, nu| {
|
|
|
|
let file = AbsolutePath::new(dirs.test().join("config.toml"));
|
|
|
|
|
|
|
|
nu.with_config(&file);
|
|
|
|
nu.with_files(vec![FileWithContent(
|
|
|
|
"config.toml",
|
|
|
|
"skip_welcome_message = true",
|
|
|
|
)]);
|
|
|
|
|
|
|
|
assert_that!(
|
|
|
|
nu.pipeline("echo $nu.config-path"),
|
2021-06-17 21:59:58 +02:00
|
|
|
says().stdout(&file.display_path())
|
2021-03-15 08:26:30 +01:00
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|
2021-03-29 10:27:51 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn scope_variable_with_alias_present() {
|
|
|
|
Playground::setup("scope_variable_alias_test_1", |dirs, nu| {
|
|
|
|
let file = AbsolutePath::new(dirs.test().join("config.toml"));
|
|
|
|
|
|
|
|
nu.with_config(&file);
|
|
|
|
nu.with_files(vec![FileWithContent(
|
|
|
|
"config.toml",
|
|
|
|
"skip_welcome_message = true",
|
|
|
|
)]);
|
|
|
|
|
|
|
|
assert_that!(
|
|
|
|
nu.pipeline("alias t = time; echo $scope.aliases | get t"),
|
2021-06-17 21:59:58 +02:00
|
|
|
says().stdout("time")
|
2021-03-29 10:27:51 +02:00
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn scope_variable_with_correct_number_of_aliases_present() {
|
|
|
|
Playground::setup("scope_variable_alias_test_2", |dirs, nu| {
|
|
|
|
let file = AbsolutePath::new(dirs.test().join("config.toml"));
|
|
|
|
|
|
|
|
nu.with_config(&file);
|
|
|
|
nu.with_files(vec![FileWithContent(
|
|
|
|
"config.toml",
|
|
|
|
"skip_welcome_message = true",
|
|
|
|
)]);
|
|
|
|
|
|
|
|
assert_that!(
|
|
|
|
nu.pipeline("alias v = version; alias t = time; echo $scope.aliases | length -c"),
|
2021-06-17 21:59:58 +02:00
|
|
|
says().stdout("2")
|
2021-03-29 10:27:51 +02:00
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|
2021-04-12 04:38:47 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn scope_variable_with_command_present() {
|
|
|
|
Playground::setup("scope_commands_test_1", |dirs, nu| {
|
|
|
|
let file = AbsolutePath::new(dirs.test().join("config.toml"));
|
|
|
|
|
|
|
|
nu.with_config(&file);
|
|
|
|
nu.with_files(vec![FileWithContent(
|
|
|
|
"config.toml",
|
|
|
|
"skip_welcome_message = true",
|
|
|
|
)]);
|
|
|
|
|
|
|
|
assert_that!(
|
|
|
|
nu.pipeline("def meaning-of-life [--number: int] { echo $number }; echo $scope.commands | get meaning-of-life"),
|
2021-06-17 21:59:58 +02:00
|
|
|
says().stdout("--number")
|
2021-04-12 04:38:47 +02:00
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|