Skip to content

Commit d871674

Browse files
jdutanttarleb
authored andcommitted
Makefile changes and doc
Makefile: use a FORMAT variable and loops to generate/test multiple expected files. Use a 'regenerate' target rather than the name of the output file. Regenerate target files before creating a release. README.md: document the regenerate target and FORMAT variable.
1 parent 90fe0d1 commit d871674

File tree

3 files changed

+51
-22
lines changed

3 files changed

+51
-22
lines changed

Makefile

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ DIFF = diff
1010
# Use a POSIX sed with ERE ('v' is specific to GNU sed)
1111
SED := sed $(shell sed v </dev/null >/dev/null 2>&1 && echo " --posix") -E
1212

13+
# Pandoc formats for test outputs
14+
ifeq "$(FORMAT)" ""
15+
FORMAT = native
16+
endif
17+
1318
# Directory containing the Quarto extension
1419
QUARTO_EXT_DIR = _extensions/$(FILTER_NAME)
1520
# The extension's name. Used in the Quarto extension metadata
@@ -41,22 +46,27 @@ help:
4146
# Test
4247
#
4348

44-
## Test that running the filter on the sample input yields expected output
49+
## Test that running the filter on the sample input yields expected outputs
4550
# The automatic variable `$<` refers to the first dependency
4651
# (i.e., the filter file).
4752
# let `test` be a PHONY target so that it is run each time it's called.
4853
.PHONY: test
4954
test: $(FILTER_FILE) test/input.md test/test.yaml
50-
$(PANDOC) --defaults test/test.yaml | \
51-
$(DIFF) test/expected.native -
52-
55+
@for ext in $(FORMAT) ; do \
56+
$(PANDOC) --defaults test/test.yaml --to $$ext | \
57+
$(DIFF) test/expected.$$ext - ; \
58+
done
5359

54-
## Re-generate the expected output
55-
# This file **must not** be a dependency of the `test` target, as that
60+
## Generate the expected output
61+
# This target **must not** be a dependency of the `test` target, as that
5662
# would cause it to be regenerated on each run, making the test
5763
# pointless.
58-
test/expected.native: $(FILTER_FILE) test/input.md test/test.yaml
59-
$(PANDOC) --defaults test/test.yaml --output=$@
64+
.PHONY: generate
65+
generate: $(FILTER_FILE) test/input.md test/test.yaml
66+
@for ext in $(FORMAT) ; do \
67+
$(PANDOC) --defaults test/test.yaml --to $$ext \
68+
--output test/expected.$$ext ; \
69+
done
6070

6171
#
6272
# Website
@@ -132,7 +142,7 @@ $(QUARTO_EXT_DIR)/$(FILTER_FILE): $(FILTER_FILE) $(QUARTO_EXT_DIR)
132142

133143
## Sets a new release (uses VERSION macro if defined)
134144
.PHONY: release
135-
release: quarto-extension
145+
release: quarto-extension regenerate
136146
git commit -am "Release $(FILTER_NAME) $(VERSION)"
137147
git tag v$(VERSION) -m "$(FILTER_NAME) $(VERSION)"
138148
@echo 'Do not forget to push the tag back to github with `git push --tags`'

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ first two steps, everything else is up to you.
5353
will know what to expect. You may also want to update the URLs
5454
in the links above to match your repository.
5555

56+
4. [ ] (optional) **Choose default test output formats**. Replace
57+
the `FORMAT=native` line in Makefile with your desired default
58+
output formats for tests, e.g. `FORMAT=html latex`. These must
59+
be possible values of Pandoc's `--to` option.
60+
5661
4. [ ] (optional) **Setup Quarto extension**: This step is
5762
recommended if you want to make it easy for [Quarto][] users to
5863
install and use your filter: Quarto expects the filter to be
@@ -82,21 +87,36 @@ targets while keeping the general structure.
8287
Use the Makefile with `make ...`, where `...` denotes one of the
8388
targets listed in this section.
8489

85-
#### `test`
90+
#### `generate`
91+
92+
(Re)generate test output files. This target runs your filter on the
93+
file `test/input.md` and generates one or more output files
94+
`test/expected.<FORMAT>` (`native` by default).
95+
96+
Change desired output formats by replacing the Makefile's `FORMAT=...`
97+
line with e.g. `FORMAT=html docx`. These must be possible values of
98+
Pandoc's `--to` option.
99+
100+
You can also set `FORMAT` on the command line to regenerate files in
101+
specific output formats:
86102

87-
Tests the filter. This target runs your filter on file
88-
`test/input.md` and compares the result with
89-
`test/expected.native`. The latter file is also a valid make
90-
target; invoke it to regenerate the expected output.
103+
```bash
104+
make regenerate FORMAT=docx
105+
```
106+
107+
Files are generated using the Pandoc default options given in
108+
`test/test.yaml`. This file is provided by default but you may want
109+
to check it into source control and modify it as needed.
110+
111+
#### `test`
91112

92-
You may want to modify this target if your filter is intended for
93-
a specific output format. E.g., if the filter only works for HTML
94-
output, you may choose to replace `test/expected.native` with
95-
`test/expected.html`, and to compare that file instead.
113+
Tests the filter. This target runs your filter on the file
114+
`test/input.md` using Pandoc options `test/test.yaml` and compares
115+
the result with one or more `test/expected.<FORMAT>` files
116+
(`native` by default).
96117

97-
The test configs are kept in file `test/test.yaml`. The file is
98-
generated on demand, but you may want to check it into source
99-
control and modify it as needed.
118+
See the `regenerate` target on how to change default `FORMAT` values
119+
or passing it on the command lines.
100120

101121
#### `quarto-extension`
102122

test/test.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
input-files: ["test/input.md"]
2-
to: native
32
standalone: true
43
filters:
54
- {type: lua, path: greetings.lua}

0 commit comments

Comments
 (0)