mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-23 04:55:15 +00:00
Shell: Add some tests for heredocs
This commit is contained in:
parent
3048274f5e
commit
d70f25bbe5
Notes:
sideshowbarker
2024-07-18 18:54:38 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/d70f25bbe5c Pull-request: https://github.com/SerenityOS/serenity/pull/6725 Issue: https://github.com/SerenityOS/serenity/issues/4283
1 changed files with 74 additions and 0 deletions
74
Userland/Shell/Tests/heredocs.sh
Normal file
74
Userland/Shell/Tests/heredocs.sh
Normal file
|
@ -0,0 +1,74 @@
|
|||
#!/bin/sh
|
||||
|
||||
source $(dirname "$0")/test-commons.inc
|
||||
|
||||
# Simple usage, single doc
|
||||
echo <<-test > sh.doc.test
|
||||
this is a test
|
||||
test
|
||||
if test "$(cat sh.doc.test)" != "this is a test" {
|
||||
fail "Could not use normal interpolated heredoc"
|
||||
}
|
||||
|
||||
echo <<-'test' > sh.doc.test
|
||||
this is a test
|
||||
test
|
||||
if test "$(cat sh.doc.test)" != "this is a test" {
|
||||
fail "Could not use normal non-interpolated heredoc"
|
||||
}
|
||||
|
||||
echo <<~test > sh.doc.test
|
||||
this is a test
|
||||
test
|
||||
if test "$(cat sh.doc.test)" != "this is a test" {
|
||||
fail "Could not use normal dedented heredoc"
|
||||
}
|
||||
|
||||
echo <<~'test' > sh.doc.test
|
||||
this is a test
|
||||
test
|
||||
if test "$(cat sh.doc.test)" != "this is a test" {
|
||||
fail "Could not use normal non-interpolated dedented heredoc"
|
||||
}
|
||||
|
||||
var=test
|
||||
echo <<-test > sh.doc.test
|
||||
this is a $var
|
||||
test
|
||||
if test "$(cat sh.doc.test)" != "this is a test" {
|
||||
fail "Could not use interpolated heredoc with interpolation"
|
||||
}
|
||||
|
||||
echo <<~test > sh.doc.test
|
||||
this is a $var
|
||||
test
|
||||
if test "$(cat sh.doc.test)" != "this is a test" {
|
||||
fail "Could not use dedented interpolated heredoc with interpolation"
|
||||
}
|
||||
|
||||
# Multiple heredocs
|
||||
echo <<-test <<-test2 > sh.doc.test
|
||||
contents for test
|
||||
test
|
||||
contents for test2
|
||||
test2
|
||||
if test "$(cat sh.doc.test)" != "contents for test contents for test2" {
|
||||
fail "Could not use two heredocs"
|
||||
}
|
||||
|
||||
# Why would you do this you crazy person?
|
||||
if test "$(echo <<~text)" != "test" {
|
||||
test
|
||||
text
|
||||
fail "Could not use heredocs in a weird place"
|
||||
}
|
||||
|
||||
# Now let's try something _really_ weird!
|
||||
if test "$(echo <<~test1)" != "$(echo <<~test2)" { fail "The parser forgot about heredocs after a block, oops" }
|
||||
test
|
||||
test1
|
||||
test
|
||||
test2
|
||||
|
||||
rm -f sh.doc.test
|
||||
pass
|
Loading…
Add table
Reference in a new issue