Refactor: introduce 2 associated functions to PipelineData (#16233)

# Description
As title: this pr is try to introduce 2 functions to `PipelineData`:
1. PipelineData::list_stream --> create a PipelineData::ListStream
2. PipelineData::byte_stream -> create a PipelineData::ByteStream
And use these functions everywhere.

### Reason behind this change
I tried to implement `pipefail` feature, but this would required to
change `PipelineData` from enum to struct. So use these functions can
reduce diff if I finally change to struct. [Discord message
here](https://discord.com/channels/601130461678272522/615962413203718156/1396999539000479784)
is my plan.

# User-Facing Changes
NaN

# Tests + Formatting
NaN

# After Submitting
NaN
This commit is contained in:
Wind
2025-08-02 09:30:30 +08:00
committed by GitHub
parent ee5b5bd39e
commit eb8d2d3206
126 changed files with 299 additions and 304 deletions

View File

@ -2,9 +2,9 @@ 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::{
PipelineData, Span, Spanned, Type, Value,
ast::Call,
engine::{EngineState, Stack, StateWorkingSet},
PipelineData, Span, Spanned, Type, Value,
};
use std::path::PathBuf;
@ -33,19 +33,14 @@ fn test_start_valid_url() {
// Create call for: `start https://www.example.com`
let path = "https://www.example.com".to_string();
let span = Span::test_data();
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,
);
let result = Start.run(&engine_state, &mut stack, &call, PipelineData::empty);
assert!(
result.is_ok(),
@ -61,17 +56,9 @@ fn test_start_valid_local_path() {
// 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 call = Call::test("start", vec![Value::string(path, span)]);
let result = Start.run(
&engine_state,
&mut stack,
&call,
PipelineData::Empty,
);
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
@ -90,17 +77,9 @@ fn test_start_nonexistent_local_path() {
// 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 call = Call::test("start", vec![Value::string(path, span)]);
let result = Start.run(
&engine_state,
&mut stack,
&call,
PipelineData::Empty,
);
let result = Start.run(&engine_state, &mut stack, &call, PipelineData::empty);
// We expect an error since the file does not exist
assert!(
@ -117,4 +96,5 @@ fn test_start_nonexistent_local_path() {
} else {
panic!("Unexpected error type, expected ShellError::GenericError");
}
}
}