Skip to content

Commit

Permalink
Split man.test to make tests pass without oniguruma (#2722)
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny authored Jul 17, 2023
1 parent 4b3090a commit 9e4c715
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 71 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ src/decNumber/** linguist-vendored
src/lexer.[ch] linguist-generated=true
src/parser.[ch] linguist-generated=true
tests/man.test linguist-generated=true
tests/manonig.test linguist-generated=true
jq.1.prebuilt linguist-generated=true
docs/Pipfile.lock linguist-generated=true
14 changes: 8 additions & 6 deletions .github/workflows/manpage.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name: Building man page and man.test
name: Building man page, man.test, manonig.test
on:
push:
paths:
- '.github/workflows/manpage.yml'
- 'docs/**'
- 'tests/man.test'
- 'tests/manonig.test'
- 'jq.1.prebuilt'
pull_request:
paths:
- '.github/workflows/manpage.yml'
- 'docs/**'
- 'tests/man.test'
- 'tests/manonig.test'
- 'jq.1.prebuilt'

jobs:
Expand All @@ -33,14 +35,14 @@ jobs:
run: |
autoreconf -i
./configure --enable-docs
- name: Build man page and man.test
- name: Build man page, man.test, manonig.test
run: |
mv jq.1.prebuilt jq.1.old
rm -f tests/man.test
make jq.1.prebuilt tests/man.test
- name: Make sure that jq.1.prebuilt and man.test are up to date
rm -f tests/man.test manonig.test
make jq.1.prebuilt tests/man.test tests/manonig.test
- name: Make sure that jq.1.prebuilt, man.test, manonig.test are up to date
run: |
git diff --exit-code tests/man.test
git diff --exit-code tests/man.test tests/manonig.test
# skip build date in jq.1.prebuilt
test -s jq.1.prebuilt
diff -- <(tail -n +3 jq.1.old) <(tail -n +3 jq.1.prebuilt)
16 changes: 10 additions & 6 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ endif

### Tests (make check)

TESTS = tests/optionaltest tests/mantest tests/jqtest tests/onigtest tests/shtest tests/utf8test tests/base64test
TESTS = tests/optionaltest tests/mantest tests/jqtest tests/shtest tests/utf8test tests/base64test
AM_TESTS_ENVIRONMENT = JQ=$(abs_builddir)/jq NO_VALGRIND=$(NO_VALGRIND)

# This is a magic make variable that causes it to treat tests/man.test as a
Expand All @@ -150,9 +150,9 @@ check_DATA = tests/man.test
# Making changes to the manpage without having the python deps means your
# tests won't run. If you aren't making changes to the examples, you probably
# don't care. But if you are, then you need to run the tests anyway.
tests/man.test: $(srcdir)/docs/content/manual/manual.yml
tests/man.test tests/manonig.test: $(srcdir)/docs/content/manual/manual.yml
if ENABLE_DOCS
$(AM_V_GEN) ( cd ${abs_srcdir}/docs; $(PIPENV) run python build_mantests.py ) > $@
$(AM_V_GEN) ( cd ${abs_srcdir}/docs; $(PIPENV) run python build_mantests.py )
else
@echo Changes to the manual.yml require docs to be enabled to update the manual test.
@echo As a result, the manual test is out of date.
Expand Down Expand Up @@ -186,6 +186,10 @@ endif

AM_CFLAGS += $(onig_CFLAGS)

if WITH_ONIGURUMA
TESTS += tests/onigtest tests/manonigtest
endif

### Packaging

docs/site.yml: configure.ac
Expand Down Expand Up @@ -216,9 +220,9 @@ EXTRA_DIST = $(DOC_FILES) $(man_MANS) $(TESTS) $(TEST_LOG_COMPILER) \
tests/modules/test_bind_order2.jq \
tests/onig.supp tests/local.supp \
tests/setup tests/torture/input0.json \
tests/optional.test tests/man.test tests/jq.test \
tests/onig.test tests/base64.test tests/utf8-truncate.jq \
tests/jq-f-test.sh
tests/optional.test tests/man.test tests/manonig.test \
tests/jq.test tests/onig.test tests/base64.test \
tests/utf8-truncate.jq tests/jq-f-test.sh

AM_DISTCHECK_CONFIGURE_FLAGS=--disable-maintainer-mode --with-oniguruma=builtin

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ homepage and on the github release page, https://github.com/jqlang/jq/releases
If you're building directly from the latest git, you'll need flex,
bison (3.0 or newer), libtool, make, automake, and autoconf installed.
To get regexp support you'll also need to install Oniguruma or clone it as a
git submodule as per the instructions below.
(note that jq's tests require regexp support to pass). To build, run:
git submodule as per the instructions below. To build, run:

git submodule update --init # if building from git to get oniguruma
autoreconf -i # if building from git
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ AC_SUBST(onig_CFLAGS)
AC_SUBST(onig_LDFLAGS)

AM_CONDITIONAL([BUILD_ONIGURUMA], [test "x$build_oniguruma" = xyes])
AM_CONDITIONAL([WITH_ONIGURUMA], [test "x$with_oniguruma" != xno])
AC_SUBST([BUNDLER], ["$bundle_cmd"])

AC_CONFIG_MACRO_DIRS([config/m4 m4])
Expand Down
12 changes: 6 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ The jq website, manpages and some of the tests are generated from this
directory. The manual is a YAML file in `content/manual`.

To build the documentation (including building the jq manpage), you'll
need python3 and pipenv. You can install pipenv like so:
need `python3` and `pipenv`. You can install `pipenv` like so:

pip install pipenv

Though, you may need to say pip3 instead, depending on your system. Once
you have pipenv installed, you can install the dependencies by running
`pipenv install` from the `docs` directory.
Though, you may need to say `pip3` instead, depending on your system. Once
you have `pipenv` installed, you can install the dependencies by running
`pipenv sync` from the `docs` directory.

Also, you may need to run `virtualenv -p /usr/bin/python3 venv/` and
then `source venv/bin/activate`, and only then `pipenv install`.
then `source venv/bin/activate`, and only then `pipenv sync`.

Once this is done, rerun `./configure` in the jq root directory and then
the Makefile will be able to generate the jq manpage. You can also just
run `pipenv run build_manpage.py` in the `docs` directory to build the
`jq.1` page manually, and `pipenv run build_mantests.py` to build the
contents of `tests/man.test`.
contents of `tests/man.test` and `tests/manonig.test`.

To build the website, run `pipenv run ./build_website.py` from inside
the `docs` directory.
20 changes: 14 additions & 6 deletions docs/build_mantests.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#!/usr/bin/env python3
import yaml
import re

with open("content/manual/manual.yml") as f:
manual = yaml.safe_load(f)
regex_program_pattern = re.compile(
r'\b(?:test|match|capture|scan|split|splits|sub|gsub)\s*\(')

with open('content/manual/manual.yml') as source, \
open('../tests/man.test', 'w') as man, \
open('../tests/manonig.test', 'w') as manonig:
manual = yaml.safe_load(source)
for section in manual.get('sections', []):
for entry in section.get('entries', []):
for example in entry.get('examples', []):
print(example.get('program', '').replace('\n', ' '))
print(example.get('input', ''))
program = example.get('program', '').replace('\n', ' ')
out = manonig if regex_program_pattern.search(program) else man
print(program, file=out)
print(example.get('input', ''), file=out)
for s in example.get('output', []):
print(s)
print('')
print(s, file=out)
print('', file=out)
44 changes: 0 additions & 44 deletions tests/man.test

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions tests/manonig.test

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/manonigtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

. "${0%/*}/setup" "$@"

$VALGRIND $Q $JQ -L "$mods" --run-tests $JQBASEDIR/tests/manonig.test
2 changes: 1 addition & 1 deletion tests/mantest
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
. "${0%/*}/setup" "$@"

# We set PAGER because there's a mantest for `env` that uses it.
env PAGER=less $VALGRIND $Q $JQ -L "$mods" --run-tests < $JQBASEDIR/tests/man.test
env PAGER=less $VALGRIND $Q $JQ -L "$mods" --run-tests $JQBASEDIR/tests/man.test

0 comments on commit 9e4c715

Please sign in to comment.