Skip to content

Commit

Permalink
add fixture to test heredoc integration
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Feb 28, 2024
1 parent 60d1ce4 commit 88ec837
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/bashly/extensions/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ def indent(offset)
heredoc_marker = nil

map do |line|
if line =~ /<<-?(\w+)\n?$/
heredoc_marker = $1
"#{indentation}#{line}"
elsif heredoc_marker && /^#{heredoc_marker}\n?$/.match?(line)
heredoc_marker = nil
if heredoc_marker
heredoc_marker = nil if /^#{heredoc_marker}\n?$/.match?(line)
line
else
heredoc_marker ? line : "#{indentation}#{line}"
heredoc_marker = $1 if line =~ /<<-?(\w+)\n?$/
"#{indentation}#{line}"
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions spec/approvals/fixtures/heredoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
+ bundle exec bashly generate
creating user files in src
skipped src/root_command.sh (exists)
created ./cli
run ./cli --help to test your bash script
+ ./cli
unindented
multiline
heredoc text
also unindented
1 indentation
2 indentations
3 indentations

3 indentations with empty line above
also unindented
1 change: 1 addition & 0 deletions spec/fixtures/workspaces/heredoc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cli
1 change: 1 addition & 0 deletions spec/fixtures/workspaces/heredoc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This fixture tests that heredoc blocks are kept unindented
3 changes: 3 additions & 0 deletions spec/fixtures/workspaces/heredoc/src/bashly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: cli
help: Sample application to test heredoc
version: 0.1.0
18 changes: 18 additions & 0 deletions spec/fixtures/workspaces/heredoc/src/root_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
echo unindented

cat <<-FIRST_BLOCK
multiline
heredoc text
FIRST_BLOCK

echo also unindented

cat <<-SECOND_BLOCK
1 indentation
2 indentations
3 indentations
3 indentations with empty line above
SECOND_BLOCK

echo also unindented
8 changes: 8 additions & 0 deletions spec/fixtures/workspaces/heredoc/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -x

bundle exec bashly generate

./cli

0 comments on commit 88ec837

Please sign in to comment.