use nu_test_support::prelude::*;
const CODE_STRESS_INTERNALS_COMPLETE: &str = r#"
let plugin_path = (which nu_plugin_stress_internals).path.0
nu --no-config-file --plugins $plugin_path --commands "stress_internals" | complete
"#;
#[test]
#[serial]
#[deps(NU_PLUGIN_STRESS_INTERNALS)]
fn test_stdio() -> Result {
let result: CompleteResult = test().run(CODE_STRESS_INTERNALS_COMPLETE)?;
assert_contains("local_socket_path: None", &result.stdout);
Ok(())
}
#[test]
#[serial]
#[deps(NU, NU_PLUGIN_STRESS_INTERNALS)]
fn test_local_socket() -> Result {
let result: CompleteResult = test()
.env("STRESS_ADVERTISE_LOCAL_SOCKET", "1")
.run(CODE_STRESS_INTERNALS_COMPLETE)?;
assert_eq!(result.exit_code, 0);
assert_contains("--stdio", &result.stderr);
assert_contains("--local-socket", &result.stderr);
assert_contains("local_socket_path: Some", &result.stdout);
Ok(())
}
#[test]
#[serial]
#[deps(NU_PLUGIN_STRESS_INTERNALS)]
fn test_failing_local_socket_fallback() -> Result {
let result: CompleteResult = test()
.env("STRESS_ADVERTISE_LOCAL_SOCKET", "1")
.env("STRESS_REFUSE_LOCAL_SOCKET", "1")
.run(CODE_STRESS_INTERNALS_COMPLETE)?;
assert_eq!(result.exit_code, 0);
let mut count_stdio = 0;
let mut count_local_socket = 0;
for line in result.stderr.lines() {
if line.contains("--stdio") {
count_stdio += 1;
}
if line.contains("--local-socket") {
count_local_socket += 1;
}
}
assert_eq!(1, count_local_socket, "count of --local-socket");
assert_eq!(2, count_stdio, "count of --stdio");
assert_contains("local_socket_path: None", &result.stdout);
Ok(())
}
#[test]
#[serial]
#[deps(NU_PLUGIN_STRESS_INTERNALS)]
fn test_exit_before_hello_stdio() -> Result {
let result: CompleteResult = test()
.env("STRESS_EXIT_EARLY", "1")
.run(CODE_STRESS_INTERNALS_COMPLETE)?;
assert_ne!(result.exit_code, 0);
Ok(())
}
#[test]
#[serial]
#[deps(NU_PLUGIN_STRESS_INTERNALS)]
fn test_exit_early_stdio() -> Result {
let result: CompleteResult = test()
.env("STRESS_EXIT_EARLY", "1")
.run(CODE_STRESS_INTERNALS_COMPLETE)?;
assert_ne!(result.exit_code, 0);
assert_contains("--stdio", &result.stderr);
Ok(())
}
#[test]
#[serial]
#[deps(NU_PLUGIN_STRESS_INTERNALS)]
fn test_exit_early_local_socket() -> Result {
let result: CompleteResult = test()
.env("STRESS_ADVERTISE_LOCAL_SOCKET", "1")
.env("STRESS_EXIT_EARLY", "1")
.run(CODE_STRESS_INTERNALS_COMPLETE)?;
assert_ne!(result.exit_code, 0);
assert_contains("--local-socket", &result.stderr);
Ok(())
}
#[test]
#[serial]
#[deps(NU_PLUGIN_STRESS_INTERNALS)]
fn test_wrong_version() -> Result {
let result: CompleteResult = test()
.env("STRESS_WRONG_VERSION", "1")
.run(CODE_STRESS_INTERNALS_COMPLETE)?;
assert_ne!(result.exit_code, 0);
assert_contains("version", &result.stderr);
assert_contains("0.0.0", &result.stderr);
Ok(())
}