Split man.test to make tests pass without oniguruma (#2722)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by itchyny · committed by GitHub · parent 4b3090a · Browse files · 11 files·+91 added−71 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+91 added−71 removed
- tests:+50 added−45 removed
- other:+41 added−26 removed
Provenance
- Commit
9e4c715- Tree
e7f23b7- Author
itchyny <itchyny@cybozu.co.jp>- Committer
GitHub <noreply@github.com>- Parent
4b3090a
11 files changed+91 added−71 removed
modified:.github/workflows/manpage.yml+8 added-6 removed
11234567891011121314151617181914 unmodified lines3435363736383940394041414243444345464748name: Building man page and man.testname: Building man page, man.test, manonig.teston: 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: manpages:14 unmodified lines - name: Configure 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)modified:docs/build_mantests.py+14 added-6 removed
1 #!/usr/bin/env python32 import yaml3+import re4 4-with open("content/manual/manual.yml") as f:5- manual = yaml.safe_load(f)5+regex_program_pattern = re.compile(6+ r'\b(?:test|match|capture|scan|split|splits|sub|gsub)\s*\(')7+8+with open('content/manual/manual.yml') as source, \9+ open('../tests/man.test', 'w') as man, \10+ open('../tests/manonig.test', 'w') as manonig:11+ manual = yaml.safe_load(source)12 for section in manual.get('sections', []):13 for entry in section.get('entries', []):14 for example in entry.get('examples', []):9- print(example.get('program', '').replace('\n', ' '))10- print(example.get('input', ''))15+ program = example.get('program', '').replace('\n', ' ')16+ out = manonig if regex_program_pattern.search(program) else man17+ print(program, file=out)18+ print(example.get('input', ''), file=out)19 for s in example.get('output', []):12- print(s)13- print('')20+ print(s, file=out)21+ print('', file=out)modified:docs/README.md+6 added-6 removed
3 unmodified lines4567889101112131412131415161717181920212223232425263 unmodified linesThe jq website, manpages and some of the tests are generated from thisdirectory. The manual is a YAML file in `content/manual`.
To build the documentation (including building the jq manpage), you'llneed 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. Onceyou 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. Onceyou 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/` andthen `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 thenthe Makefile will be able to generate the jq manpage. You can also justrun `pipenv run build_manpage.py` in the `docs` directory to build the`jq.1` page manually, and `pipenv run build_mantests.py` to build thecontents of `tests/man.test`.contents of `tests/man.test` and `tests/manonig.test`.
To build the website, run `pipenv run ./build_website.py` from insidethe `docs` directory.modified:tests/man.test-44 removed
562 unmodified lines563 implode564 [65, 66, 67]565 "ABC"566 567-split(", ")568-"a, b,c,d, e, "569-["a","b,c,d","e",""]570-567 join(", ")568 ["a","b,c,d","e"]569 "a, b,c,d, e"570 36 unmodified lines607 walk(if type == "array" then sort else . end)608 [[4, 1, 7], [8, 5, 2], [3, 6, 9]]609 [[1,4,7],[2,5,8],[3,6,9]]610 615-walk( if type == "object" then with_entries( .key |= sub( "^_+"; "") ) else . end )616-[ { "_a": { "__b": 2 } } ]617-[{"a":{"b":2}}]618-611 $ENV.PAGER612 null613 "less"614 131 unmodified lines746 [.[] | tonumber?]747 ["1", "invalid", "3", 4]748 [1, 3, 4]749 758-test("foo")759-"foo"760-true761-762-.[] | test("a b c # spaces are ignored"; "ix")763-["xabcd", "ABC"]764-true765-true766-767-match("(abc)+"; "g")768-"abc abc"769-{"offset": 0, "length": 3, "string": "abc", "captures": [{"offset": 0, "length": 3, "string": "abc", "name": null}]}770-{"offset": 4, "length": 3, "string": "abc", "captures": [{"offset": 4, "length": 3, "string": "abc", "name": null}]}771-772-match("foo")773-"foo bar foo"774-{"offset": 0, "length": 3, "string": "foo", "captures": []}775-776-match(["foo", "ig"])777-"foo bar FOO"778-{"offset": 0, "length": 3, "string": "foo", "captures": []}779-{"offset": 8, "length": 3, "string": "FOO", "captures": []}780-781-match("foo (?<bar123>bar)? foo"; "ig")782-"foo bar foo foo foo"783-{"offset": 0, "length": 11, "string": "foo bar foo", "captures": [{"offset": 4, "length": 3, "string": "bar", "name": "bar123"}]}784-{"offset": 12, "length": 8, "string": "foo foo", "captures": [{"offset": -1, "length": 0, "string": null, "name": "bar123"}]}785-786-[ match("."; "g")] | length787-"abc"788-3789-790-capture("(?<a>[a-z]+)-(?<n>[0-9]+)")791-"xyzzy-14"792-{ "a": "xyzzy", "n": "14" }793-750 .bar as $x | .foo | . + $x751 {"foo":10, "bar":200}752 210753 109 unmodified linesadded:tests/manonig.test+44 added
1+split(", ")2+"a, b,c,d, e, "3+["a","b,c,d","e",""]4+5+walk( if type == "object" then with_entries( .key |= sub( "^_+"; "") ) else . end )6+[ { "_a": { "__b": 2 } } ]7+[{"a":{"b":2}}]8+9+test("foo")10+"foo"11+true12+13+.[] | test("a b c # spaces are ignored"; "ix")14+["xabcd", "ABC"]15+true16+true17+18+match("(abc)+"; "g")19+"abc abc"20+{"offset": 0, "length": 3, "string": "abc", "captures": [{"offset": 0, "length": 3, "string": "abc", "name": null}]}21+{"offset": 4, "length": 3, "string": "abc", "captures": [{"offset": 4, "length": 3, "string": "abc", "name": null}]}22+23+match("foo")24+"foo bar foo"25+{"offset": 0, "length": 3, "string": "foo", "captures": []}26+27+match(["foo", "ig"])28+"foo bar FOO"29+{"offset": 0, "length": 3, "string": "foo", "captures": []}30+{"offset": 8, "length": 3, "string": "FOO", "captures": []}31+32+match("foo (?<bar123>bar)? foo"; "ig")33+"foo bar foo foo foo"34+{"offset": 0, "length": 11, "string": "foo bar foo", "captures": [{"offset": 4, "length": 3, "string": "bar", "name": "bar123"}]}35+{"offset": 12, "length": 8, "string": "foo foo", "captures": [{"offset": -1, "length": 0, "string": null, "name": "bar123"}]}36+37+[ match("."; "g")] | length38+"abc"39+340+41+capture("(?<a>[a-z]+)-(?<n>[0-9]+)")42+"xyzzy-14"43+{ "a": "xyzzy", "n": "14" }44+added:tests/manonigtest+5 added
1+#!/bin/sh2+3+. "${0%/*}/setup" "$@"4+5+$VALGRIND $Q $JQ -L "$mods" --run-tests $JQBASEDIR/tests/manonig.testmodified:tests/mantest+1 added-1 removed
1 unmodified line2 3 . "${0%/*}/setup" "$@"4 5 # We set PAGER because there's a mantest for `env` that uses it.6-env PAGER=less $VALGRIND $Q $JQ -L "$mods" --run-tests < $JQBASEDIR/tests/man.test6+env PAGER=less $VALGRIND $Q $JQ -L "$mods" --run-tests $JQBASEDIR/tests/man.testmodified:.gitattributes+1 added
7 unmodified lines8 # generated files9 src/lexer.[ch] linguist-generated=true10 src/parser.[ch] linguist-generated=true11 tests/man.test linguist-generated=true12+tests/manonig.test linguist-generated=true13 jq.1.prebuilt linguist-generated=true14 docs/Pipfile.lock linguist-generated=truemodified:configure.ac+1 added
286 unmodified lines287 AC_SUBST(onig_CFLAGS)288 AC_SUBST(onig_LDFLAGS)289 290 AM_CONDITIONAL([BUILD_ONIGURUMA], [test "x$build_oniguruma" = xyes])291+AM_CONDITIONAL([WITH_ONIGURUMA], [test "x$with_oniguruma" != xno])292 AC_SUBST([BUNDLER], ["$bundle_cmd"])293 294 AC_CONFIG_MACRO_DIRS([config/m4 m4])295 AC_CONFIG_FILES([Makefile libjq.pc])2 unmodified linesmodified:Makefile.am+10 added-6 removed
132 unmodified lines133 endif134 135 ### Tests (make check)136 137-TESTS = tests/optionaltest tests/mantest tests/jqtest tests/onigtest tests/shtest tests/utf8test tests/base64test137+TESTS = tests/optionaltest tests/mantest tests/jqtest tests/shtest tests/utf8test tests/base64test138 AM_TESTS_ENVIRONMENT = JQ=$(abs_builddir)/jq NO_VALGRIND=$(NO_VALGRIND)139 140 # This is a magic make variable that causes it to treat tests/man.test as a141 # DATA-type dependency for the check target. As a result, it will attempt to7 unmodified lines149 # As a result, we need to rebuild the tests if the manual has been updated.150 # Making changes to the manpage without having the python deps means your151 # tests won't run. If you aren't making changes to the examples, you probably152 # don't care. But if you are, then you need to run the tests anyway.153-tests/man.test: $(srcdir)/docs/content/manual/manual.yml153+tests/man.test tests/manonig.test: $(srcdir)/docs/content/manual/manual.yml154 if ENABLE_DOCS155- $(AM_V_GEN) ( cd ${abs_srcdir}/docs; $(PIPENV) run python build_mantests.py ) > $@155+ $(AM_V_GEN) ( cd ${abs_srcdir}/docs; $(PIPENV) run python build_mantests.py )156 else157 @echo Changes to the manual.yml require docs to be enabled to update the manual test.158 @echo As a result, the manual test is out of date.159 endif25 unmodified lines185 endif186 187 AM_CFLAGS += $(onig_CFLAGS)188 189+if WITH_ONIGURUMA190+TESTS += tests/onigtest tests/manonigtest191+endif192+193 ### Packaging194 195 docs/site.yml: configure.ac196 sed 's/^jq_version: .*/jq_version: "$(VERSION)"/' $@ > $@.new22 unmodified lines219 tests/modules/test_bind_order1.jq \220 tests/modules/test_bind_order2.jq \221 tests/onig.supp tests/local.supp \222 tests/setup tests/torture/input0.json \219- tests/optional.test tests/man.test tests/jq.test \220- tests/onig.test tests/base64.test tests/utf8-truncate.jq \221- tests/jq-f-test.sh223+ tests/optional.test tests/man.test tests/manonig.test \224+ tests/jq.test tests/onig.test tests/base64.test \225+ tests/utf8-truncate.jq tests/jq-f-test.sh226 227 AM_DISTCHECK_CONFIGURE_FLAGS=--disable-maintainer-mode --with-oniguruma=builtin228 229 # README.md is expected in GitHub projects, good stuff in it, so we'll14 unmodified linesmodified:README.md+1 added-2 removed
18 unmodified lines19 20 If you're building directly from the latest git, you'll need flex,21 bison (3.0 or newer), libtool, make, automake, and autoconf installed.22 To get regexp support you'll also need to install Oniguruma or clone it as a23-git submodule as per the instructions below.24-(note that jq's tests require regexp support to pass). To build, run:23+git submodule as per the instructions below. To build, run:24 25 git submodule update --init # if building from git to get oniguruma26 autoreconf -i # if building from git27 ./configure --with-oniguruma=builtin46 unmodified lines