feat: add rust-script
This commit is contained in:
112
external/rust-script/tests/tests/expr.rs
vendored
Normal file
112
external/rust-script/tests/tests/expr.rs
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
#[test]
|
||||
fn test_expr_0() {
|
||||
let out = rust_script!("-e", with_output_marker!("0")).unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("0") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expr_comma() {
|
||||
let out = rust_script!("-e", with_output_marker!("[1, 2, 3]")).unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("[1, 2, 3]") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expr_dnc() {
|
||||
let out = rust_script!("-e", "swing begin").unwrap();
|
||||
assert!(!out.success());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expr_temporary() {
|
||||
let out = rust_script!("-e", "[1].iter().max()").unwrap();
|
||||
assert!(out.success());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expr_dep() {
|
||||
let out = rust_script!(
|
||||
"-d",
|
||||
"boolinator=0.1.0",
|
||||
"-e",
|
||||
with_output_marker!(
|
||||
prelude "use boolinator::Boolinator;";
|
||||
"true.as_some(1)"
|
||||
)
|
||||
)
|
||||
.unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Some(1)") => ()
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expr_panic() {
|
||||
let out = rust_script!("-e", with_output_marker!("panic!()")).unwrap();
|
||||
assert!(!out.success());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expr_qmark() {
|
||||
let code = with_output_marker!("\"42\".parse::<i32>()?.wrapping_add(1)");
|
||||
let out = rust_script!("-e", code).unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("43") => ()
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expr_template() {
|
||||
let template_dir = "tests/data/templates";
|
||||
let out = rust_script!(
|
||||
#[env(RUST_SCRIPT_DEBUG_TEMPLATE_PATH=template_dir)]
|
||||
"-t",
|
||||
"shout",
|
||||
"-e",
|
||||
with_output_marker!(r#""no way? no way!""#)
|
||||
)
|
||||
.unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("NO WAY? NO WAY!") => ()
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expr_template_with_deps() {
|
||||
let template_dir = "tests/data/templates";
|
||||
let out = rust_script!(
|
||||
#[env(RUST_SCRIPT_DEBUG_TEMPLATE_PATH=template_dir)]
|
||||
"-t",
|
||||
"boolinate",
|
||||
"-e",
|
||||
with_output_marker!(r#"true"#)
|
||||
)
|
||||
.unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Some(())") => ()
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expr_template_override_expr() {
|
||||
let template_dir = "tests/data/templates/override";
|
||||
let out = rust_script!(
|
||||
#[env(RUST_SCRIPT_DEBUG_TEMPLATE_PATH=template_dir)]
|
||||
"-e",
|
||||
with_output_marker!(r#"true"#)
|
||||
)
|
||||
.unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Some(())") => ()
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
15
external/rust-script/tests/tests/others.rs
vendored
Normal file
15
external/rust-script/tests/tests/others.rs
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
#[test]
|
||||
fn test_version() {
|
||||
let out = rust_script!("--version").unwrap();
|
||||
assert!(out.success());
|
||||
scan!(&out.stdout;
|
||||
("rust-script", &::std::env::var("CARGO_PKG_VERSION").unwrap(), .._) => ()
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_clear_cache() {
|
||||
let out = rust_script!("--clear-cache").unwrap();
|
||||
assert!(out.success());
|
||||
}
|
||||
235
external/rust-script/tests/tests/script.rs
vendored
Normal file
235
external/rust-script/tests/tests/script.rs
vendored
Normal file
@@ -0,0 +1,235 @@
|
||||
#[test]
|
||||
fn test_script_explicit() {
|
||||
let out = rust_script!("-d", "boolinator", "tests/data/script-explicit.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Some(1)") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_features() {
|
||||
let out = rust_script!("--features", "dont-panic", "tests/data/script-features.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Keep calm and borrow check.") => ()
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let out = rust_script!("tests/data/script-features.rs").unwrap();
|
||||
assert!(!out.success());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_full_block() {
|
||||
let out = rust_script!("tests/data/script-full-block.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Some(1)") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_full_line() {
|
||||
let out = rust_script!("tests/data/script-full-line.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Some(1)") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_full_line_without_main() {
|
||||
let out = rust_script!("tests/data/script-full-line-without-main.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Some(1)") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_invalid_doc_comment() {
|
||||
let out = rust_script!("tests/data/script-invalid-doc-comment.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Hello, World!") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_no_deps() {
|
||||
let out = rust_script!("tests/data/script-no-deps.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Hello, World!") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_short() {
|
||||
let out = rust_script!("tests/data/script-short.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Some(1)") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_short_without_main() {
|
||||
let out = rust_script!("tests/data/script-short-without-main.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Some(1)") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_test() {
|
||||
let out = rust_script!("--test", "tests/data/script-test.rs").unwrap();
|
||||
assert!(out.success());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_hyphens() {
|
||||
use scan_rules::scanner::QuotedString;
|
||||
let out = rust_script!("--", "tests/data/script-args.rs", "-NotAnArg").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("[0]:", let _: QuotedString, "[1]:", let arg: QuotedString) => {
|
||||
assert_eq!(arg, "-NotAnArg");
|
||||
}
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_hyphens_without_separator() {
|
||||
use scan_rules::scanner::QuotedString;
|
||||
let out = rust_script!("tests/data/script-args.rs", "-NotAnArg").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("[0]:", let _: QuotedString, "[1]:", let arg: QuotedString) => {
|
||||
assert_eq!(arg, "-NotAnArg");
|
||||
}
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_has_weird_chars() {
|
||||
let out = rust_script!("tests/data/script-has.weird§chars!.rs").unwrap();
|
||||
assert!(out.success());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_cs_env() {
|
||||
let out = rust_script!("tests/data/script-cs-env.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Ok") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_including_relative() {
|
||||
let out = rust_script!("tests/data/script-including-relative.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("hello, including script") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_with_same_name_as_dependency() {
|
||||
let out = rust_script!("tests/data/time.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Hello") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_without_main_question_mark() {
|
||||
let out = rust_script!("tests/data/question-mark").unwrap();
|
||||
assert!(out
|
||||
.stderr
|
||||
.starts_with("Error: Os { code: 2, kind: NotFound, message:"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_async_main() {
|
||||
let out = rust_script!("tests/data/script-async-main.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Some(1)") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pub_fn_main() {
|
||||
let out = rust_script!("tests/data/pub-fn-main.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Some(1)") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cargo_target_dir_env() {
|
||||
let out = rust_script!("tests/data/cargo-target-dir-env.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("true") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_outer_line_doc() {
|
||||
let out = rust_script!("tests/data/outer-line-doc.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Some(1)") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_whitespace_before_main() {
|
||||
let out = rust_script!("tests/data/whitespace-before-main.rs").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("hello, world") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stable_toolchain() {
|
||||
let out = rust_script!(
|
||||
"--toolchain-version",
|
||||
"stable",
|
||||
"tests/data/script-unstable-feature.rs"
|
||||
)
|
||||
.unwrap();
|
||||
assert!(out.stderr.contains("`#![feature]` may not be used"));
|
||||
assert!(!out.success());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nightly_toolchain() {
|
||||
let out = rust_script!(
|
||||
"--toolchain-version",
|
||||
"nightly",
|
||||
"tests/data/script-unstable-feature.rs"
|
||||
)
|
||||
.unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("`#![feature]` *may* be used!") => ()
|
||||
)
|
||||
.unwrap();
|
||||
assert!(out.success());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_same_flags() {
|
||||
let out = rust_script!("tests/data/same-flags.rs", "--help").unwrap();
|
||||
scan!(out.stdout_output();
|
||||
("Argument: --help") => ()
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
Reference in New Issue
Block a user