Remove test-bins feature.

This commit is contained in:
Andrés N. Robalino 2020-05-17 22:52:56 -05:00
parent d1b1438ce5
commit f18424a6f6
13 changed files with 134 additions and 126 deletions

View file

@ -46,13 +46,13 @@ steps:
echo "##vso[task.prependpath]$HOME/.cargo/bin"
rustup component add rustfmt
displayName: Install Rust
- bash: RUSTFLAGS="-D warnings" cargo test --all --features stable,test-bins
- bash: RUSTFLAGS="-D warnings" cargo test --all --features stable
condition: eq(variables['style'], 'unflagged')
displayName: Run tests
- bash: RUSTFLAGS="-D warnings" cargo clippy --all --features=stable -- -D clippy::result_unwrap_used -D clippy::option_unwrap_used
condition: eq(variables['style'], 'unflagged')
displayName: Check clippy lints
- bash: NUSHELL_ENABLE_ALL_FLAGS=1 RUSTFLAGS="-D warnings" cargo test --all --features stable,test-bins
- bash: NUSHELL_ENABLE_ALL_FLAGS=1 RUSTFLAGS="-D warnings" cargo test --all --features stable
condition: eq(variables['style'], 'canary')
displayName: Run tests
- bash: NUSHELL_ENABLE_ALL_FLAGS=1 RUSTFLAGS="-D warnings" cargo clippy --all --features=stable -- -D clippy::result_unwrap_used -D clippy::option_unwrap_used

View file

@ -60,9 +60,6 @@ serde = { version = "1.0.110", features = ["derive"] }
nu-build = { version = "0.14.1", path = "./crates/nu-build" }
[features]
# Test executables
test-bins = []
default = ["sys", "ps", "textview", "inc", "str"]
stable = ["default", "starship-prompt", "binaryview", "match", "tree", "average", "parse", "post", "fetch", "clipboard-cli", "trash-support", "start"]
@ -88,31 +85,6 @@ clipboard-cli = ["nu-cli/clipboard-cli"]
starship-prompt = ["nu-cli/starship-prompt"]
trash-support = ["nu-cli/trash-support"]
[[bin]]
name = "fail"
path = "crates/nu-test-support/src/bins/fail.rs"
required-features = ["test-bins"]
[[bin]]
name = "chop"
path = "crates/nu-test-support/src/bins/chop.rs"
required-features = ["test-bins"]
[[bin]]
name = "cococo"
path = "crates/nu-test-support/src/bins/cococo.rs"
required-features = ["test-bins"]
[[bin]]
name = "nonu"
path = "crates/nu-test-support/src/bins/nonu.rs"
required-features = ["test-bins"]
[[bin]]
name = "iecho"
path = "crates/nu-test-support/src/bins/iecho.rs"
required-features = ["test-bins"]
# Core plugins that ship with `cargo install nu` by default
# Currently, Cargo limits us to installing only one binary
# unless we use [[bin]], so we use this as a workaround

View file

@ -26,7 +26,7 @@ mod git;
mod path;
mod shell;
mod stream;
mod utils;
pub mod utils;
pub use crate::cli::{
cli, create_default_context, load_plugins, run_pipeline_standalone, run_vec_of_pipelines,

View file

@ -1,5 +1,6 @@
pub mod data;
pub mod data_processing;
pub mod test_bins;
use crate::path::canonicalize;
use nu_errors::ShellError;
@ -21,6 +22,7 @@ pub struct ValueResource {
impl ValueResource {}
#[derive(Default)]
pub struct ValueStructure {
pub resources: Vec<ValueResource>,
}
@ -96,6 +98,7 @@ pub struct Res {
impl Res {}
#[derive(Default)]
pub struct FileStructure {
pub resources: Vec<Res>,
}

View file

@ -0,0 +1,94 @@
use std::io::{self, BufRead, Write};
pub fn cococo() {
let args: Vec<String> = args();
if args.len() > 1 {
// Write back out all the arguments passed
// if given at least 1 instead of chickens
// speaking co co co.
let mut arguments = args.iter();
arguments.next();
for arg in arguments {
println!("{}", &arg);
}
} else {
println!("cococo");
}
}
pub fn nonu() {
args().iter().skip(1).for_each(|arg| print!("{}", arg));
}
pub fn iecho() {
// println! panics if stdout gets closed, whereas writeln gives us an error
let mut stdout = io::stdout();
let _ = args()
.iter()
.skip(1)
.cycle()
.try_for_each(|v| writeln!(stdout, "{}", v));
}
pub fn fail() {
std::process::exit(1);
}
pub fn chop() {
if did_chop_arguments() {
// we are done and don't care about standard input.
std::process::exit(0);
}
// if no arguments given, chop from standard input and exit.
let stdin = io::stdin();
let mut stdout = io::stdout();
for line in stdin.lock().lines() {
if let Ok(given) = line {
let chopped = if given.is_empty() {
&given
} else {
let to = given.len() - 1;
&given[..to]
};
if let Err(_e) = writeln!(stdout, "{}", chopped) {
break;
}
}
}
std::process::exit(0);
}
fn did_chop_arguments() -> bool {
let args: Vec<String> = args();
if args.len() > 1 {
let mut arguments = args.iter();
arguments.next();
for arg in arguments {
let chopped = if arg.is_empty() {
&arg
} else {
let to = arg.len() - 1;
&arg[..to]
};
println!("{}", chopped);
}
return true;
}
false
}
fn args() -> Vec<String> {
// skip (--testbin bin_name args)
std::env::args().skip(2).collect()
}

View file

@ -1,47 +0,0 @@
use std::io::{self, BufRead, Write};
fn main() {
if did_chop_arguments() {
// we are done and don't care about standard input.
std::process::exit(0);
}
// if no arguments given, chop from standard input and exit.
let stdin = io::stdin();
let mut stdout = io::stdout();
for line in stdin.lock().lines() {
if let Ok(given) = line {
if let Err(_e) = writeln!(stdout, "{}", chop(&given)) {
break;
}
}
}
std::process::exit(0);
}
fn chop(word: &str) -> &str {
if word.is_empty() {
word
} else {
let to = word.len() - 1;
&word[..to]
}
}
fn did_chop_arguments() -> bool {
let args: Vec<String> = std::env::args().collect();
if args.len() > 1 {
let mut arguments = args.iter();
arguments.next();
for arg in arguments {
println!("{}", chop(arg));
}
return true;
}
false
}

View file

@ -1,17 +0,0 @@
fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() > 1 {
// Write back out all the arguments passed
// if given at least 1 instead of chickens
// speaking co co co.
let mut arguments = args.iter();
arguments.next();
for arg in arguments {
println!("{}", &arg);
}
} else {
println!("cococo");
}
}

View file

@ -1,3 +0,0 @@
fn main() {
std::process::exit(1);
}

View file

@ -1,13 +0,0 @@
use std::io::{self, Write};
fn main() {
let args: Vec<String> = std::env::args().collect();
// println! panics if stdout gets closed, whereas writeln gives us an error
let mut stdout = io::stdout();
let _ = args
.iter()
.skip(1)
.cycle()
.try_for_each(|v| writeln!(stdout, "{}", v));
}

View file

@ -1,3 +0,0 @@
fn main() {
std::env::args().skip(1).for_each(|arg| print!("{}", arg));
}

View file

@ -1,5 +1,6 @@
use clap::{App, Arg};
use log::LevelFilter;
use nu_cli::utils::test_bins as binaries;
use nu_cli::{create_default_context, EnvironmentSyncer};
use std::error::Error;
use std::fs::File;
@ -16,6 +17,14 @@ fn main() -> Result<(), Box<dyn Error>> {
.possible_values(&["error", "warn", "info", "debug", "trace"])
.takes_value(true),
)
.arg(
Arg::with_name("testbin")
.hidden(true)
.long("testbin")
.value_name("TESTBIN")
.possible_values(&["cococo", "iecho", "fail", "nonu", "chop"])
.takes_value(true),
)
.arg(
Arg::with_name("commands")
.short("c")
@ -48,6 +57,19 @@ fn main() -> Result<(), Box<dyn Error>> {
)
.get_matches();
if let Some(bin) = matches.value_of("testbin") {
match bin {
"cococo" => binaries::cococo(),
"iecho" => binaries::iecho(),
"fail" => binaries::fail(),
"nonu" => binaries::nonu(),
"chop" => binaries::chop(),
_ => unreachable!(),
}
return Ok(());
}
let loglevel = match matches.value_of("loglevel") {
None => LevelFilter::Warn,
Some("error") => LevelFilter::Error,

View file

@ -74,7 +74,7 @@ mod it_evaluation {
ls
| sort-by name
| get name
| cococo $it
| nu --testbin cococo $it
| lines
| nth 1
| echo $it
@ -101,7 +101,7 @@ mod it_evaluation {
r#"
open nu_candies.txt
| lines
| chop $it
| nu --testbin chop $it
| lines
| nth 1
| echo $it
@ -145,7 +145,7 @@ mod stdin_evaluation {
let actual = nu!(
cwd: ".",
pipeline(r#"
nonu "where's the nuline?"
nu --testbin nonu "where's the nuline?"
| count
"#
));
@ -158,9 +158,9 @@ mod stdin_evaluation {
let stdout = nu!(
cwd: ".",
pipeline(r#"
iecho yes
| chop
| chop
nu --testbin iecho yes
| nu --testbin chop
| nu --testbin chop
| lines
| first 1
"#
@ -177,7 +177,7 @@ mod external_words {
#[test]
fn relaxed_external_words() {
let actual = nu!(cwd: ".", r#"
cococo joturner@foo.bar.baz
nu --testbin cococo joturner@foo.bar.baz
"#);
assert_eq!(actual.out, "joturner@foo.bar.baz");
@ -227,7 +227,7 @@ mod tilde_expansion {
let actual = nu!(
cwd: ".",
r#"
cococo ~
nu --testbin cococo ~
"#
);
@ -242,7 +242,7 @@ mod tilde_expansion {
let actual = nu!(
cwd: ".",
r#"
cococo "1~1"
nu --testbin cococo "1~1"
"#
);

View file

@ -24,7 +24,7 @@ fn takes_rows_of_nu_value_strings_and_pipes_it_to_stdin_of_external() {
open nu_times.csv
| get name
| ^echo $it
| chop
| nu --testbin chop
| nth 3
| echo $it
"#
@ -90,7 +90,7 @@ fn invocation_handles_dot() {
echo $(open nu_times.csv)
| get name
| ^echo $it
| chop
| nu --testbin chop
| nth 3
| echo $it
"#
@ -104,7 +104,7 @@ fn invocation_handles_dot() {
fn can_process_one_row_from_internal_and_pipes_it_to_stdin_of_external() {
let actual = nu!(
cwd: ".",
r#"echo "nushelll" | chop"#
r#"echo "nushelll" | nu --testbin chop"#
);
assert_eq!(actual.out, "nushell");