Skip to content

Commit 4224f8c

Browse files
authored
Fail the build if there are any errors (#663)
We used to fail when building a book resulted in any `WARNING`s or the process the builds the book exits with a non-0 status. This was fine when we were only using `AsciiDoc` because `a2x` would always exit with a non-0 status if it output any `ERROR`s. But Asciidoctor will happily exit with a 0 status after output errors! If that happens, we should fail to build the book. This change does exectly that. And it adds an integration test that attempt to build a file with a missing include. That tests this change.
1 parent 03e76cc commit 4224f8c

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

integtest/Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ check: \
1414
includes_expected_files includes_same_files \
1515
beta_expected_files beta_same_files \
1616
experimental_expected_files experimental_same_files \
17+
missing_include_fails_asciidoc missing_include_fails_asciidoctor \
1718
readme_expected_files readme_same_files \
1819
small_all_expected_files
1920

@@ -70,10 +71,30 @@ experimental_expected_files: /tmp/experimental_asciidoc
7071
./html_diff /tmp/$*_asciidoc/$$file /tmp/$*_asciidoctor/$$file; \
7172
done
7273

74+
# Build the docs into the target
7375
define BD=
7476
/docs_build/build_docs.pl --in_standard_docker --out $@
7577
endef
7678

79+
# Build the docs into a temporary directory
80+
define BD_DUMMY=
81+
/docs_build/build_docs.pl --in_standard_docker --out /tmp/dummy
82+
endef
83+
84+
.PHONY: missing_include_fails_asciidoc
85+
missing_include_fails_asciidoc: missing_include.asciidoc
86+
set +e; \
87+
$(BD_DUMMY) --doc missing_include.asciidoc > /tmp/out 2>&1; \
88+
test $$? -eq 255
89+
$(call GREP,'WARNING: missing_include.asciidoc: line 7: include file not found: /docs_build/integtest/missing.asciidoc',/tmp/out)
90+
91+
.PHONY: missing_include_fails_asciidoctor
92+
missing_include_fails_asciidoctor: missing_include.asciidoc
93+
set +e; \
94+
$(BD_DUMMY) --asciidoctor --doc missing_include.asciidoc > /tmp/out 2>&1; \
95+
test $$? -eq 255
96+
$(call GREP,'ERROR: missing_include.asciidoc: line 7: include file not found: /docs_build/integtest/missing.asciidoc',/tmp/out)
97+
7798
/tmp/readme_asciidoc: /docs_build/README.asciidoc
7899
$(BD) --doc /docs_build/README.asciidoc
79100

@@ -126,3 +147,18 @@ small_all_expected_files: /tmp/small_all
126147

127148
# Check out the files we just built
128149
git clone /tmp/small_all.git /tmp/small_all
150+
151+
define GREP=
152+
# grep for a string in a file, outputting the whole file if there isn't
153+
# a match.
154+
[ -e $(2) ] || { \
155+
echo "can't find $(2)"; \
156+
ls $$(dirname $(2)); \
157+
false; \
158+
}
159+
grep $(1) $(2) > /dev/null || { \
160+
echo "Couldn't find $(1) in $(2):"; \
161+
cat $(2); \
162+
false; \
163+
}
164+
endef

integtest/missing_include.asciidoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
= Title
2+
3+
== Chapter
4+
5+
I include missing between here
6+
7+
include::missing.asciidoc[]
8+
9+
and here.

lib/ES/Util.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ sub build_single {
294294
sub _check_build_error {
295295
#===================================
296296
my ( $output, $died, $lenient ) = @_;
297-
my $warned = grep {/^(a2x|asciidoc(tor)?): (WARNING):/} split "\n", $output;
297+
my $warned = grep {/^(a2x|asciidoc(tor)?): (WARNING|ERROR):/} split "\n", $output;
298298

299299
return unless $died || $warned;
300300

0 commit comments

Comments
 (0)