Skip to content

Commit e94d3aa

Browse files
committed
Document that heredoc doesn't work in prep section
1 parent b5f6667 commit e94d3aa

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

tests/acceptance/04_examples/README.org

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,58 @@ and =#+end_src= tags.
1414
*NOTE:* Agent output should be *identical* between a normal execution and a dry
1515
run. This means that some examples are poor candidates for automatic testing.
1616

17+
=prep= sections can not handle /heredoc/, so don't try to use them to setup an
18+
environment, instead, use echo to build up a file.
19+
20+
#+CAPTION: Example error showing issue with usage of heredoc in prep
21+
#+begin_example
22+
Q: "...r/bin/perl /hom": processing /home/nickanderson/Northern.Tech/CFEngine/core/tests/acceptance/../../examples/execresult.cf: Running prep 'EOF'Can't exec "EOF": No such file or directory at /home/nickanderson/Northern.Tech/CFEngine/core/tests/acceptance/../../examples/remake_outputs.pl line 227.
23+
#+end_example
24+
25+
So, don't do this:
26+
27+
#+CAPTION: BAD: example using heredoc inside prep section
28+
#+begin_example
29+
,#+begin_src prep
30+
#@ ```
31+
#@ rm -rf /tmp/testhere
32+
#@ mkdir -p /tmp/testhere
33+
#@ touch /tmp/testhere/a
34+
#@ touch /tmp/testhere/b
35+
#@ touch /tmp/testhere/c
36+
#@ touch /tmp/testhere/d
37+
#@ touch /tmp/testhere/e
38+
#@ cat << EOF >/tmp/testhere/echo-stdout-and-stderr
39+
#@ #!/usr/bin/env sh
40+
#@ echo stderr >&2
41+
#@ echo stdout
42+
#@ EOF
43+
#@ chmod +x /tmp/testhere/echo-stdout-and-stderr
44+
#@ ```
45+
,#+end_src
46+
#+end_example
47+
48+
Instead, do this:
49+
50+
#+CAPTION: GOOD example using echo instead of heredoc during setup
51+
#+begin_example
52+
,#+begin_src prep
53+
#@ ```
54+
#@ rm -rf /tmp/testhere
55+
#@ mkdir -p /tmp/testhere
56+
#@ touch /tmp/testhere/a
57+
#@ touch /tmp/testhere/b
58+
#@ touch /tmp/testhere/c
59+
#@ touch /tmp/testhere/d
60+
#@ touch /tmp/testhere/e
61+
#@ echo "#!/usr/bin/env sh" >/tmp/testhere/echo-stdout-and-stderr
62+
#@ echo "echo stderr >&2" >>/tmp/testhere/echo-stdout-and-stderr
63+
#@ echo "echo stdout" >>/tmp/testhere/echo-stdout-and-stderr
64+
#@ chmod +x /tmp/testhere/echo-stdout-and-stderr
65+
#@ ```
66+
,#+end_src
67+
#+end_example
68+
1769
** Troubleshooting Outputs Test Failures
1870
This section is primarily intended for CFEngine Staff as not all build output is
1971
publicly available.
@@ -83,8 +135,9 @@ normal run and a dry-run where warnings are promised.
83135
#+NAME: Testing classfiltercsv()
84136
#+CALL: test_check_outputs()
85137

138+
86139
:DRAWER:
87-
#+RESULTS: Testing classfiltercsv()
140+
#+RESULTS: Example Testing classfiltercsv()
88141
#+begin_example
89142
======================================================================
90143
Testsuite started at 2019-04-13 18:40:54

0 commit comments

Comments
 (0)