mirror of
https://github.com/nushell/nushell
synced 2024-11-10 07:04:13 +00:00
Update tests Playground (#12134)
<!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> It looks like `Playground` and `Director` in nu-tests-support haven't gotten much love recently, so this PR is for updating them to work with newer Nushell versions. - `Director` adds a `--skip-plugins` argument before running `nu`, but that doesn't exist anymore, so I removed it. - `Director` also adds a `--perf` argument, which also doesn't exist anymore. I added `--log-level info` instead to get the performance output. - It doesn't seem like anyone was using `playground::matchers`, and it used the [hamcrest2](https://github.com/Valloric/hamcrest2-rust) crate, which appears to be unmaintained, so I got rid of that (and the `hamcrest2` dependency). - Inside `tests/fixtures/playground/config` were two files in the old config format: `default.toml` and `startup.toml`. I removed those too. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> None, these changes only mess with tests. # 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` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # 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. -->
This commit is contained in:
parent
af98b0219d
commit
c90640411d
8 changed files with 15 additions and 187 deletions
68
Cargo.lock
generated
68
Cargo.lock
generated
|
@ -1711,16 +1711,6 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hamcrest2"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49f837c62de05dc9cc71ff6486cd85de8856a330395ae338a04bfcefe5e91075"
|
||||
dependencies = [
|
||||
"num 0.2.1",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hash32"
|
||||
version = "0.3.1"
|
||||
|
@ -2813,7 +2803,7 @@ dependencies = [
|
|||
"nu-engine",
|
||||
"nu-parser",
|
||||
"nu-protocol",
|
||||
"num 0.4.1",
|
||||
"num",
|
||||
"polars",
|
||||
"polars-arrow",
|
||||
"polars-io",
|
||||
|
@ -3171,7 +3161,6 @@ dependencies = [
|
|||
name = "nu-test-support"
|
||||
version = "0.91.1"
|
||||
dependencies = [
|
||||
"hamcrest2",
|
||||
"nu-glob",
|
||||
"nu-path",
|
||||
"nu-utils",
|
||||
|
@ -3262,42 +3251,17 @@ dependencies = [
|
|||
"nu-protocol",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36"
|
||||
dependencies = [
|
||||
"num-bigint 0.2.6",
|
||||
"num-complex 0.2.4",
|
||||
"num-integer",
|
||||
"num-iter",
|
||||
"num-rational 0.2.4",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af"
|
||||
dependencies = [
|
||||
"num-bigint 0.4.4",
|
||||
"num-complex 0.4.4",
|
||||
"num-bigint",
|
||||
"num-complex",
|
||||
"num-integer",
|
||||
"num-iter",
|
||||
"num-rational 0.4.1",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-integer",
|
||||
"num-rational",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
|
@ -3312,16 +3276,6 @@ dependencies = [
|
|||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-complex"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-complex"
|
||||
version = "0.4.4"
|
||||
|
@ -3362,18 +3316,6 @@ dependencies = [
|
|||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-rational"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-bigint 0.2.6",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-rational"
|
||||
version = "0.4.1"
|
||||
|
@ -3381,7 +3323,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-bigint 0.4.4",
|
||||
"num-bigint",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
|
|
@ -19,4 +19,3 @@ nu-utils = { path = "../nu-utils", version = "0.91.1" }
|
|||
num-format = "0.4"
|
||||
which = { workspace = true }
|
||||
tempfile = { workspace = true }
|
||||
hamcrest2 = "0.3"
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
mod director;
|
||||
pub mod matchers;
|
||||
pub mod nu_process;
|
||||
mod play;
|
||||
|
||||
|
@ -7,6 +6,5 @@ mod play;
|
|||
mod tests;
|
||||
|
||||
pub use director::Director;
|
||||
pub use matchers::says;
|
||||
pub use nu_process::{Executable, NuProcess, NuResult, Outcome};
|
||||
pub use play::{Dirs, EnvironmentVariable, Playground};
|
||||
|
|
|
@ -60,15 +60,14 @@ impl Director {
|
|||
process.cwd(working_directory);
|
||||
}
|
||||
|
||||
process.arg("--skip-plugins");
|
||||
process.arg("--no-history");
|
||||
if let Some(config_file) = self.config.as_ref() {
|
||||
process.args(&[
|
||||
"--config-file",
|
||||
"--config",
|
||||
config_file.to_str().expect("failed to convert."),
|
||||
]);
|
||||
}
|
||||
process.arg("--perf");
|
||||
process.args(&["--log-level", "info"]);
|
||||
|
||||
director.executable = Some(process);
|
||||
director
|
||||
|
|
|
@ -1,102 +0,0 @@
|
|||
use hamcrest2::core::{MatchResult, Matcher};
|
||||
use std::fmt;
|
||||
use std::str;
|
||||
|
||||
use super::nu_process::Outcome;
|
||||
use super::{Director, Executable};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Play {
|
||||
stdout_expectation: Option<String>,
|
||||
}
|
||||
|
||||
impl fmt::Display for Play {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "play")
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Play {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "play")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn says() -> Play {
|
||||
Play {
|
||||
stdout_expectation: None,
|
||||
}
|
||||
}
|
||||
|
||||
trait CheckerMatchers {
|
||||
fn output(&self, actual: &Outcome) -> MatchResult;
|
||||
fn std(&self, actual: &[u8], expected: Option<&str>, description: &str) -> MatchResult;
|
||||
fn stdout(&self, actual: &Outcome) -> MatchResult;
|
||||
}
|
||||
|
||||
impl CheckerMatchers for Play {
|
||||
fn output(&self, actual: &Outcome) -> MatchResult {
|
||||
self.stdout(actual)
|
||||
}
|
||||
|
||||
fn stdout(&self, actual: &Outcome) -> MatchResult {
|
||||
self.std(&actual.out, self.stdout_expectation.as_deref(), "stdout")
|
||||
}
|
||||
|
||||
fn std(&self, actual: &[u8], expected: Option<&str>, description: &str) -> MatchResult {
|
||||
let out = match expected {
|
||||
Some(out) => out,
|
||||
None => return Ok(()),
|
||||
};
|
||||
let actual =
|
||||
str::from_utf8(actual).map_err(|_| format!("{description} was not utf8 encoded"))?;
|
||||
|
||||
if actual != out {
|
||||
return Err(format!(
|
||||
"not equal:\n actual: {actual}\n expected: {out}\n\n"
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Matcher<Outcome> for Play {
|
||||
fn matches(&self, output: Outcome) -> MatchResult {
|
||||
self.output(&output)
|
||||
}
|
||||
}
|
||||
|
||||
impl Matcher<Director> for Play {
|
||||
fn matches(&self, mut director: Director) -> MatchResult {
|
||||
self.matches(&mut director)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Matcher<&'a mut Director> for Play {
|
||||
fn matches(&self, director: &'a mut Director) -> MatchResult {
|
||||
if director.executable().is_none() {
|
||||
return Err(format!("no such process {director}"));
|
||||
}
|
||||
|
||||
let res = director.execute();
|
||||
|
||||
match res {
|
||||
Ok(out) => self.output(&out),
|
||||
Err(err) => {
|
||||
if let Some(out) = &err.output {
|
||||
return self.output(out);
|
||||
}
|
||||
|
||||
Err(format!("could not exec process {director}: {err:?}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Play {
|
||||
pub fn stdout(mut self, expected: &str) -> Self {
|
||||
self.stdout_expectation = Some(expected.to_string());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ pub struct Playground<'a> {
|
|||
root: TempDir,
|
||||
tests: String,
|
||||
cwd: PathBuf,
|
||||
config: PathBuf,
|
||||
config: Option<PathBuf>,
|
||||
environment_vars: Vec<EnvironmentVariable>,
|
||||
dirs: &'a Dirs,
|
||||
}
|
||||
|
@ -42,10 +42,6 @@ impl Dirs {
|
|||
self.fixtures.join("formats")
|
||||
}
|
||||
|
||||
pub fn config_fixtures(&self) -> PathBuf {
|
||||
self.fixtures.join("playground/config")
|
||||
}
|
||||
|
||||
pub fn root(&self) -> &Path {
|
||||
self.root.as_path()
|
||||
}
|
||||
|
@ -97,7 +93,7 @@ impl<'a> Playground<'a> {
|
|||
root,
|
||||
tests: topic.to_string(),
|
||||
cwd: nuplay_dir,
|
||||
config: fixtures.join("playground/config/default.toml"),
|
||||
config: None,
|
||||
environment_vars: Vec::default(),
|
||||
dirs: &Dirs::default(),
|
||||
};
|
||||
|
@ -135,7 +131,7 @@ impl<'a> Playground<'a> {
|
|||
}
|
||||
|
||||
pub fn with_config(&mut self, source_file: impl AsRef<Path>) -> &mut Self {
|
||||
self.config = source_file.as_ref().to_path_buf();
|
||||
self.config = Some(source_file.as_ref().to_path_buf());
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -145,14 +141,16 @@ impl<'a> Playground<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn get_config(&self) -> &str {
|
||||
self.config.to_str().expect("could not convert path.")
|
||||
pub fn get_config(&self) -> Option<&str> {
|
||||
self.config
|
||||
.as_ref()
|
||||
.map(|cfg| cfg.to_str().expect("could not convert path."))
|
||||
}
|
||||
|
||||
pub fn build(&mut self) -> Director {
|
||||
Director {
|
||||
cwd: Some(self.dirs.test().into()),
|
||||
config: Some(self.config.clone().into()),
|
||||
config: self.config.clone().map(|cfg| cfg.into()),
|
||||
environment_vars: self.environment_vars.clone(),
|
||||
..Default::default()
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
skip_welcome_message = true
|
||||
filesize_format = "auto"
|
||||
rm_always_trash = false
|
|
@ -1,3 +0,0 @@
|
|||
skip_welcome_message = true
|
||||
|
||||
startup = ["def hello-world [] { echo 'Nu World' }"]
|
Loading…
Reference in a new issue