mirror of
https://github.com/nushell/nushell.git
synced 2025-07-12 12:26:05 +02:00
.cargo
.githooks
.github
assets
benches
clippy
crates
nu-cli
nu-cmd-base
nu-cmd-extra
nu-cmd-lang
nu-cmd-plugin
nu-color-config
nu-command
src
tests
commands
assignment
base
bytes
conversions
database
date
debug
hash_
math
move_
network
path
platform
query
random
skip
str_
take
url
alias.rs
all.rs
any.rs
append.rs
break_.rs
cal.rs
cd.rs
chunk_by.rs
chunks.rs
compact.rs
complete.rs
config_env_default.rs
config_nu_default.rs
continue_.rs
debug_info.rs
def.rs
default.rs
detect_columns.rs
do_.rs
drop.rs
du.rs
each.rs
echo.rs
empty.rs
error_make.rs
every.rs
exec.rs
export_def.rs
fill.rs
filter.rs
find.rs
first.rs
flatten.rs
for_.rs
format.rs
generate.rs
get.rs
glob.rs
griddle.rs
group_by.rs
headers.rs
help.rs
histogram.rs
ignore.rs
insert.rs
inspect.rs
interleave.rs
into_datetime.rs
into_duration.rs
into_filesize.rs
into_int.rs
job.rs
join.rs
last.rs
length.rs
let_.rs
lines.rs
loop_.rs
ls.rs
match_.rs
merge.rs
merge_deep.rs
mktemp.rs
mod.rs
mut_.rs
nu_check.rs
open.rs
par_each.rs
parse.rs
prepend.rs
print.rs
redirection.rs
reduce.rs
reject.rs
rename.rs
return_.rs
reverse.rs
rm.rs
roll.rs
rotate.rs
run_external.rs
save.rs
select.rs
semicolon.rs
seq.rs
seq_char.rs
seq_date.rs
slice.rs
sort.rs
sort_by.rs
source_env.rs
split_column.rs
split_row.rs
start.rs
stor.rs
table.rs
tee.rs
terminal.rs
to_text.rs
transpose.rs
try_.rs
ucp.rs
ulimit.rs
umkdir.rs
uname.rs
uniq.rs
uniq_by.rs
update.rs
upsert.rs
use_.rs
utouch.rs
where_.rs
which.rs
while_.rs
window.rs
with_env.rs
wrap.rs
zip.rs
format_conversions
string
main.rs
sort_utils.rs
Cargo.toml
LICENSE
README.md
nu-derive-value
nu-engine
nu-explore
nu-glob
nu-json
nu-lsp
nu-parser
nu-path
nu-plugin
nu-plugin-core
nu-plugin-engine
nu-plugin-protocol
nu-plugin-test-support
nu-pretty-hex
nu-protocol
nu-std
nu-system
nu-table
nu-term-grid
nu-test-support
nu-utils
nu_plugin_custom_values
nu_plugin_example
nu_plugin_formats
nu_plugin_gstat
nu_plugin_inc
nu_plugin_javascript
nu_plugin_nu_example
nu_plugin_polars
nu_plugin_python
nu_plugin_query
nu_plugin_stress_internals
nuon
README.md
devdocs
docker
scripts
src
tests
wix
.gitattributes
.gitignore
CITATION.cff
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Cargo.lock
Cargo.toml
Cross.toml
LICENSE
README.md
SECURITY.md
rust-toolchain.toml
toolkit.nu
typos.toml
Fixes #14960 # User-Facing Changes - The output of non-streaming values can now be interrupted with ctrl-c: ```nushell ~> use std repeat; random chars --length 100kb | repeat 2000 | str join ' ' | collect <data omitted>^C Error: × Operation interrupted ╭─[entry #1:1:61] 1 │ use std repeat; random chars --length 100kb | repeat 2000 | str join ' ' | collect · ────┬─── · ╰── This operation was interrupted ╰──── ``` - When IO errors occur while printing data, nushell no longer panics: ```diff $ nu -c "true | print" | - -Error: - x Main thread panicked. - |-> at crates/nu-protocol/src/errors/shell_error/io.rs:198:13 - `-> for unknown spans with paths, use `new_internal_with_path` +Error: nu:🐚:io::broken_pipe + + x I/O error + `-> x Broken pipe + + ,-[source:1:1] + 1 | true | print + : ^^|^ + : `-| Writing to stdout failed + : | Broken pipe + `---- ```
120 lines
3.4 KiB
Rust
120 lines
3.4 KiB
Rust
use super::*;
|
|
use nu_engine::test_help::{convert_single_value_to_cmd_args, eval_block_with_input};
|
|
use nu_engine::{current_dir, eval_expression};
|
|
use nu_protocol::{
|
|
ast::Call,
|
|
engine::{EngineState, Stack, StateWorkingSet},
|
|
PipelineData, Span, Spanned, Type, Value,
|
|
};
|
|
use std::path::PathBuf;
|
|
|
|
/// Create a minimal test engine state and stack to run commands against.
|
|
fn create_test_context() -> (EngineState, Stack) {
|
|
let mut engine_state = EngineState::new();
|
|
let mut stack = Stack::new();
|
|
|
|
// A working set is needed for storing definitions in the engine state.
|
|
let _working_set = StateWorkingSet::new(&mut engine_state);
|
|
|
|
// Add the `Start` command to the engine state so we can run it.
|
|
let start_cmd = Start;
|
|
engine_state.add_cmd(Box::new(start_cmd));
|
|
|
|
(engine_state, stack)
|
|
}
|
|
|
|
#[test]
|
|
fn test_start_valid_url() {
|
|
let (engine_state, mut stack) = create_test_context();
|
|
|
|
// For safety in tests, we won't actually open anything,
|
|
// but we can still check that the command resolves as a URL
|
|
// and attempts to run. Typically, you'd mock `open::commands` if needed.
|
|
|
|
// Create call for: `start https://www.example.com`
|
|
let path = "https://www.example.com".to_string();
|
|
let span = Span::test_data();
|
|
let call = Call::test(
|
|
"start",
|
|
// The arguments for `start` are just the path in this case
|
|
vec![Value::string(path, span)],
|
|
);
|
|
|
|
let result = Start.run(
|
|
&engine_state,
|
|
&mut stack,
|
|
&call,
|
|
PipelineData::Empty,
|
|
);
|
|
|
|
assert!(
|
|
result.is_ok(),
|
|
"Expected successful run with a valid URL, got error: {:?}",
|
|
result.err()
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_start_valid_local_path() {
|
|
let (engine_state, mut stack) = create_test_context();
|
|
|
|
// Here we'll simulate opening the current directory (`.`).
|
|
let path = ".".to_string();
|
|
let span = Span::test_data();
|
|
let call = Call::test(
|
|
"start",
|
|
vec![Value::string(path, span)],
|
|
);
|
|
|
|
let result = Start.run(
|
|
&engine_state,
|
|
&mut stack,
|
|
&call,
|
|
PipelineData::Empty,
|
|
);
|
|
|
|
// If the environment is correctly set, it should succeed.
|
|
// If you're running in a CI environment or restricted environment
|
|
// this might fail, so you may need to mock `open` calls.
|
|
assert!(
|
|
result.is_ok(),
|
|
"Expected successful run opening current directory, got error: {:?}",
|
|
result.err()
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_start_nonexistent_local_path() {
|
|
let (engine_state, mut stack) = create_test_context();
|
|
|
|
// Create an obviously invalid path
|
|
let path = "this_file_does_not_exist_hopefully.txt".to_string();
|
|
let span = Span::test_data();
|
|
let call = Call::test(
|
|
"start",
|
|
vec![Value::string(path, span)],
|
|
);
|
|
|
|
let result = Start.run(
|
|
&engine_state,
|
|
&mut stack,
|
|
&call,
|
|
PipelineData::Empty,
|
|
);
|
|
|
|
// We expect an error since the file does not exist
|
|
assert!(
|
|
result.is_err(),
|
|
"Expected an error for a non-existent file path"
|
|
);
|
|
|
|
if let Err(ShellError::GenericError { error, .. }) = result {
|
|
assert!(
|
|
error.contains("Cannot find file or URL"),
|
|
"Expected 'Cannot find file or URL' in error, found: {}",
|
|
error
|
|
);
|
|
} else {
|
|
panic!("Unexpected error type, expected ShellError::GenericError");
|
|
}
|
|
} |