Dever v0.0.2
This commit is contained in:
commit
e6e175ebcf
816 files changed
+120349
No files matched your search
@@ -0,0 +1,365 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn stdout_preserves_lines_write_errors_and_blocking_task_calls() {
|
||||
use std::process::Stdio;
|
||||
for profile in [Profile::Dev, Profile::Release] {
|
||||
let binary = build(
|
||||
"stdout",
|
||||
include_str!("stdout.dever"),
|
||||
Some(include_str!("stdout.rs.txt")),
|
||||
profile,
|
||||
);
|
||||
let output = Command::new(&binary).output().unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
assert_eq!(
|
||||
String::from_utf8(output.stdout).unwrap(),
|
||||
"雪😀\n\nfirst\nsecond\nblocking\ntask\n"
|
||||
);
|
||||
let full = fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.open("/dev/full")
|
||||
.unwrap();
|
||||
let output = Command::new(&binary)
|
||||
.arg("fail")
|
||||
.stdout(full)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let (reader, writer) = std::io::pipe().unwrap();
|
||||
drop(reader);
|
||||
let output = Command::new(&binary)
|
||||
.arg("fail")
|
||||
.stdout(Stdio::from(writer))
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stdout_command_checks_input_and_propagates_real_write_failure() {
|
||||
let binary = build(
|
||||
"stdout-command",
|
||||
include_str!("stdout.dever"),
|
||||
None,
|
||||
Profile::Dev,
|
||||
);
|
||||
let input = r#"{"text":"命令输出"}"#;
|
||||
let output = Command::new(&binary)
|
||||
.args(["main.main.line", input])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||
let response = stdout.strip_prefix("命令输出\n").unwrap();
|
||||
let response: dever_runtime::wire::serde_json::Value =
|
||||
dever_runtime::wire::serde_json::from_str(response).unwrap();
|
||||
assert_eq!(response["code"], 0);
|
||||
let output = Command::new(&binary)
|
||||
.args(["main.main.line", r#"{"text":3}"#])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(!output.status.success());
|
||||
assert!(output.stdout.is_empty());
|
||||
let full = fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.open("/dev/full")
|
||||
.unwrap();
|
||||
let output = Command::new(&binary)
|
||||
.args(["main.main.line", input])
|
||||
.stdout(full)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(!output.status.success());
|
||||
assert!(!output.stderr.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concurrent_loops_execute_ordered_results_filters_walk_and_failure() {
|
||||
for profile in [Profile::Dev, Profile::Release] {
|
||||
let binary = build(
|
||||
"concurrent",
|
||||
include_str!("concurrent.dever"),
|
||||
Some(include_str!("concurrent.rs.txt")),
|
||||
profile,
|
||||
);
|
||||
let output = Command::new(binary).output().unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn synchronous_streams_execute_short_circuit_error_release_and_blocking_consumption() {
|
||||
for profile in [Profile::Dev, Profile::Release] {
|
||||
let binary = build(
|
||||
"sync-stream",
|
||||
include_str!("sync_stream.dever"),
|
||||
Some(include_str!("sync_stream.rs.txt")),
|
||||
profile,
|
||||
);
|
||||
let output = Command::new(binary).output().unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn files_execute_shared_cursor_errors_blocking_tasks_and_resource_release() {
|
||||
for profile in [Profile::Dev, Profile::Release] {
|
||||
let binary = build(
|
||||
"file",
|
||||
include_str!("file.dever"),
|
||||
Some(include_str!("file.rs.txt")),
|
||||
profile,
|
||||
);
|
||||
let output = Command::new(binary).output().unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tokens_execute_random_secret_creation_capture_and_tasks() {
|
||||
for profile in [Profile::Dev, Profile::Release] {
|
||||
let binary = build(
|
||||
"token",
|
||||
include_str!("token.dever"),
|
||||
Some(include_str!("token.rs.txt")),
|
||||
profile,
|
||||
);
|
||||
let output = Command::new(binary).output().unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn streams_execute_single_pass_close_short_circuit_failures_and_cancellation() {
|
||||
for profile in [Profile::Dev, Profile::Release] {
|
||||
let binary = build(
|
||||
"stream",
|
||||
include_str!("stream.dever"),
|
||||
Some(include_str!("stream.rs.txt")),
|
||||
profile,
|
||||
);
|
||||
let output = Command::new(binary).output().unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn channels_execute_aliases_ownership_cancellation_and_faults() {
|
||||
for profile in [Profile::Dev, Profile::Release] {
|
||||
let binary = build(
|
||||
"channel",
|
||||
include_str!("channel.dever"),
|
||||
Some(include_str!("channel.rs.txt")),
|
||||
profile,
|
||||
);
|
||||
let output = Command::new(binary).output().unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blocking_executes_passwords_handlers_groups_capture_and_faults() {
|
||||
for profile in [Profile::Dev, Profile::Release] {
|
||||
let binary = build(
|
||||
"blocking",
|
||||
include_str!("blocking.dever"),
|
||||
Some(include_str!("blocking.rs.txt")),
|
||||
profile,
|
||||
);
|
||||
let output = Command::new(binary).output().unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cpu_parallel_executes_owned_inputs_handlers_failures_and_faults() {
|
||||
for profile in [Profile::Dev, Profile::Release] {
|
||||
let binary = build(
|
||||
"worker",
|
||||
include_str!("worker.dever"),
|
||||
Some(include_str!("worker.rs.txt")),
|
||||
profile,
|
||||
);
|
||||
let output = Command::new(binary).output().unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn async_tables_execute_branch_selection_order_handlers_walk_and_failures() {
|
||||
for profile in [Profile::Dev, Profile::Release] {
|
||||
let binary = build(
|
||||
"tasks",
|
||||
include_str!("tasks.dever"),
|
||||
Some(include_str!("tasks.rs.txt")),
|
||||
profile,
|
||||
);
|
||||
let output = Command::new(binary).output().unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spawned_tasks_execute_consumption_capture_parallel_and_faults() {
|
||||
for profile in [Profile::Dev, Profile::Release] {
|
||||
let binary = build(
|
||||
"spawn",
|
||||
include_str!("spawn.dever"),
|
||||
Some(include_str!("spawn.rs.txt")),
|
||||
profile,
|
||||
);
|
||||
let output = Command::new(binary).output().unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spawned_tasks_share_validated_settings_and_preserve_owned_inputs() {
|
||||
let source = r#"
|
||||
setting title: Text
|
||||
read() (out: Int) { out = length(title) }
|
||||
flow main() (out: Int)
|
||||
| step | kind | do |
|
||||
| task | calc | run(read()) |
|
||||
| out | calc | wait(task) |
|
||||
"#;
|
||||
let harness = r###"
|
||||
let path = std::path::Path::new(@source_path@).with_extension("json");
|
||||
std::fs::write(&path, r##"{"module":{"main":{"main":{"title":"hello"}}}}"##).unwrap();
|
||||
let settings = load_settings(&path).unwrap();
|
||||
assert_eq!(dever_runtime::task::run(true, 1, async |scope| Ok::<_, ()>(@main@(scope, &settings).await)).unwrap().unwrap(), 5);
|
||||
assert_eq!(std::sync::Arc::strong_count(&settings), 1);
|
||||
"###;
|
||||
for profile in [Profile::Dev, Profile::Release] {
|
||||
let binary = build("spawn-settings", source, Some(harness), profile);
|
||||
let output = Command::new(binary).output().unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn task_combinations_execute_timeout_race_group_and_captures() {
|
||||
for profile in [Profile::Dev, Profile::Release] {
|
||||
let binary = build(
|
||||
"combinations",
|
||||
include_str!("combinations.dever"),
|
||||
Some(include_str!("combinations.rs.txt")),
|
||||
profile,
|
||||
);
|
||||
let output = Command::new(binary).output().unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_task_settings_and_large_race_keep_concrete_codegen() {
|
||||
let source = r#"
|
||||
setting title: Text
|
||||
read() (out: Int) { out = length(title) }
|
||||
fallback() (out: Int) { out = 0 }
|
||||
flow main() (out: Int)
|
||||
| step | kind | do |
|
||||
| out | calc | timeout(run(read()), 60000, fallback) |
|
||||
expectLabel(value: Text) () { check value == "hello" else Invalid }
|
||||
flow member() ()
|
||||
| step | kind | do |
|
||||
| task | calc | run(read()) |
|
||||
| value | calc | wait(task) |
|
||||
| - | check | value == 5 else Invalid |
|
||||
flow groupConfigured() ()
|
||||
| step | kind | do |
|
||||
| tasks | calc | group(2) |
|
||||
| - | calc | run(tasks, expectLabel(title)) |
|
||||
| - | calc | run(tasks, member()) |
|
||||
| - | calc | wait(tasks) |
|
||||
flow cpuConfigured() (out: Int)
|
||||
| step | kind | do |
|
||||
| out | calc | parallel(read()) |
|
||||
"#;
|
||||
let harness = r###"
|
||||
let path = std::path::Path::new(@source_path@).with_extension("json");
|
||||
std::fs::write(&path, r##"{"module":{"main":{"main":{"title":"hello"}}}}"##).unwrap();
|
||||
let settings = load_settings(&path).unwrap();
|
||||
assert_eq!(dever_runtime::task::run(true, 1, async |scope| Ok::<_, ()>(@main@(scope, &settings).await)).unwrap().unwrap(), 5);
|
||||
dever_runtime::task::run(true, 3, async |scope| @groupConfigured@(scope, &settings).await).unwrap().unwrap();
|
||||
assert_eq!(dever_runtime::task::run(true, 1, async |scope| Ok::<_, ()>(@cpuConfigured@(scope, &settings).await)).unwrap().unwrap(), 5);
|
||||
assert_eq!(std::sync::Arc::strong_count(&settings), 1);
|
||||
"###;
|
||||
let binary = build("nested-task-settings", source, Some(harness), Profile::Dev);
|
||||
assert!(Command::new(binary).status().unwrap().success());
|
||||
let tasks = std::iter::repeat_n("run(identity(42))", 65)
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let source = format!(
|
||||
"identity(value: Int) (out: Int) {{ out = value }}\nflow main() (out: Int)\n| step | kind | do |\n| out | calc | race({tasks}) |\n"
|
||||
);
|
||||
let harness = "assert_eq!(dever_runtime::task::run(true, 65, async |scope| Ok::<_, ()>(@main@(scope).await)).unwrap().unwrap(), 42);";
|
||||
let binary = build("large-race", &source, Some(harness), Profile::Dev);
|
||||
assert!(Command::new(binary).status().unwrap().success());
|
||||
}
|
||||
Reference in new issue
Block a user