use std::sync::Arc;
use kaish_kernel::{Kernel, KernelConfig};
async fn setup() -> Arc<Kernel> {
Kernel::new(KernelConfig::isolated().with_skip_validation(true))
.expect("failed to create kernel")
.into_arc()
}
#[tokio::test]
async fn crlf_body_preserves_carriage_returns() {
let k = setup().await;
let r = k.execute("cat <<EOF\r\nhello\r\nEOF").await.expect("ok");
assert_eq!(r.text_out(), "hello\r\n");
}
#[tokio::test]
async fn bare_cr_body_preserves_carriage_returns() {
let k = setup().await;
let r = k.execute("cat <<EOF\rhello\rEOF").await.expect("ok");
assert_eq!(r.text_out(), "hello\r");
}
#[tokio::test]
async fn crlf_terminated_delimiter_still_matches() {
let k = setup().await;
let r = k.execute("cat <<EOF\nhello\nEOF\r\n").await.expect("ok");
assert_eq!(r.text_out(), "hello\n");
}
#[tokio::test]
async fn bare_cr_terminated_delimiter_still_matches() {
let k = setup().await;
let r = k.execute("cat <<EOF\nhello\nEOF\r").await.expect("ok");
assert_eq!(r.text_out(), "hello\n");
}
#[tokio::test]
async fn unterminated_heredoc_errors() {
let k = setup().await;
let err = k.execute("cat <<EOF\nhello").await.expect_err(
"unterminated heredoc must surface as an error, not silent truncation",
);
let msg = err.to_string();
assert!(
msg.contains("unterminated heredoc"),
"error should mention unterminated heredoc; got: {msg}",
);
assert!(
msg.contains("EOF"),
"error should name the expected delimiter; got: {msg}",
);
}
#[tokio::test]
async fn unterminated_heredoc_with_dash_form_errors() {
let k = setup().await;
let err = k.execute("cat <<-DONE\n\thi").await.expect_err("error expected");
let msg = err.to_string();
assert!(msg.contains("unterminated heredoc"), "got: {msg}");
assert!(msg.contains("DONE"), "got: {msg}");
}
#[tokio::test]
async fn nested_command_substitution_in_body() {
let k = setup().await;
let r = k
.execute("cat <<EOF\nvia $(echo nested)\nEOF")
.await
.expect("ok");
assert_eq!(r.text_out(), "via nested\n");
}
#[tokio::test]
async fn nested_pipeline_command_substitution_in_body() {
let k = setup().await;
let r = k
.execute("cat <<EOF\n$(echo -n HELLO | tr A-Z a-z) world\nEOF")
.await
.expect("ok");
assert_eq!(r.text_out(), "hello world\n");
}