Commit graph

133 commits

Author SHA1 Message Date
Matthew Martin
dd0cf649d1 *: Use https in URLs 2023-10-25 21:33:29 -05:00
Daniel Shahaf
c28312b9d3 Merge remote-tracking branch 'origin/master' into feature/redrawhook
* origin/master: (297 commits)
  driver: Follow-up to grandparent: Have all test suite entry points declare the mock $region_highlight.
  Use the new, unreleased zsh 'memo=' feature to remove only our own entries from $region_highlight.
  driver: Stop re-declaring $region_highlight.  It's unneeded.
  docs: regexp highlighter: Fix a wrong associative array name in the example.
  docs: Fix obs-repository link
  tests: Fix a wrong value of $PREBUFFER in a test, and add checks to prevent this from recurring.
  test harness: Fix use of an undefined variable in an error message.
  'main': Don't progress the $in_redirection staller while $in_param.
  tests: Add an XFail test for issue #712.
  'main': Highlight the parentheses of array assignments as reserved words.
  CI += zsh-5.8
  main: Add tests for arithmetic expansion
  main: Add arithmetic substitution highlighting
  changelog.md: Restore vertical whitespace before section headers.
  'main': Fix issue #677, concerning multiline aliases.
  changelog: Update through HEAD.
  'main': Further optimize argument parsing.
  'main': Optimize a hot path.
  tests: Add a performance testing script, for measuring the performance of the 'main' highlighter on a large file.
  changelog: Update through HEAD.
  test harness: Print the expected-v.-actual on every failure, not just upon cardinality failures.
  Document ZSH_HIGHLIGHT_MAXLENGTH.
  'main': Fix the last commit's bug concerning parameter elision not happening in redirects in command position.
  'main': Add a test for parameter elision not happening in redirects in command position.
  'main': Fix regression in zsh 5.3.1 and older: all precmd hooks later than z-sy-h would be aborted.
  changelog += WARN_NESTED_VAR fixes (#727, #731)
  'main': Fix a regression caused by the great-grandparent commit's WARN_NESTED_VAR fix.
  'main': Don't run `_zsh_highlight_main__type` on every non-command word.
  'make perf': Show only a cumulative datum per highligher, rather than per test file.
  'main': Don't trip WARN_NESTED_VAR.
  'main': Follow-up to previous: Document the version number, and deduplicate some option letters.
  'main': precommands += strace
  editorconfig: Fix Makefile settings
  Fix typo
  Bump copyright years.
  driver: Fix "_zsh_highlight:3: read-only variable: ret" warnings when POSIX_BUILTINS is set.
  tests: Add a test for the infinite loop fixed by each of the last two commits.
  'main': Fix expansion of positional parameters in `_zsh_highlight_main_highlighter__try_expand_parameter`.
  'main': Fix an infinite loop.
  'main': precommands += ionice(1) (from util-linux)
  driver: Simplify initialization of $zsyh_user_options in the fallback codepath.
  driver: Make sure we don't change the return value in a called function.
  'main': Make logic more robust.  No functional change.
  'main': Break out an anonymous function into a named function.
  Fix typos in comments.
  main: Add test for issue #713
  'main': Support the 'env' precommand.
  test harness: Fix the pretty-printer's padding implementation.
  Revert "test harness: Rewrite the columnar pretty-printer without external tools." and "travis: Remove bsdmainutils since column(1) has been removed, three commits ago."
  changelog: Update through HEAD.
  'main': Correctly highlight '&&' and '||' inside '[[ … ]]' conditions.
  'main': Highlight reserved words following assignments as errors.
  tests: Add tests for issue #461.
  test harness: Output the time information to the same place the test name was printed to.
  test harness: Stringify values in a more readable manner.
  tests: Add a unit test for a path specified with mixed quoting.
  tests: Add a test for issue #498, which has already been fixed.
  tests: Test that global qualifiers and command substitutions aren't evaluated.
  'main': Don't consider path_prefix in alias expansions.
  'main': Add a test for aliases to AUTO_CD directories.
  'main': Let AUTO_CD directories be highlighted with their own style.
  'main': Add an auxiliary variable for readability.
  'main': In command position, do not highlight directories (unless AUTO_CD is set) and non-executable files.
  'main': Extend tests to capture the current behaviour.
  'main': Add an XFail test for issue #202.
  'main': Highlight errors from the EQUALS option.
  'main': Let the type determination ignore global aliases when it ignores regular ones.
  'main': Add a regression test for parameters that expand to global aliases.
  'main': Enable the zsh/parameter codepath of global aliases highlighting.
  changelog: Update through HEAD.
  travis: Remove bsdmainutils since column(1) has been removed, three commits ago.
  'main': Highlight global aliases
  tests: Record current behaviour on global aliases.
  test harness: Rewrite the columnar pretty-printer without external tools.
  test harness: Fix an issue with the pretty-printed $expected_region_highlight/$region_highlight diffing.
  'main': Support the "close file descriptor" and "coproc" redirection syntaxes
  tests: Add a test for the "close file descriptor" and "coproc" redirection syntaxes
  tests: Fix the test added in the last commit.
  tests: Add a test for issue #705, concerning continuation lines.
  test harness: Let tests fail early by exiting non-zero or by setting a flag.
  test harness: Print the test name when $skip_test is set.
  test harness: Remove a bogus check.
  test harness: Fix $skip_test support, broken yesterday.
  travis: Install bsdmainutils to provide column(1).
  test harness: When the cardinality check fails, pretty-print \$expected_region_highlight and \$region_highlight.
  test harness: Don't leak options from test files to the test harness.
  test harness: Fix test failures under zsh 5.0.8 and older.
  'main': Fix a bug manifesting under zsh 5.2 and older.
  'main': Don't highlight arithmetic expansions as command substitutions.
  tests: Add a test documenting the current state, prior to introducing #704.
  test harness: Change cardinality check semantics
  test harness: No-op change to minimize the next diff.
  'main': Document additional meanings of the 'S' $braces_stack flag.
  'main': When the redirection operator '>&' or '<&' is followed by a positive integer, do not consider that as a filename; it's always a file descriptor.
  'main': Add $last_arg for "lookbehind".
  noop: Clarify comment.
  'main': Honour the MULTIOS option when applying the 'globbing' style.
  'main': Document what $in_redirection is currently used for.
  'main': The optimized cmdsubst input syntax doesn't glob.
  changelog: Fix markup.
  ...
2020-07-14 01:57:55 +00:00
Daniel Shahaf
d9a7963970 driver: Follow-up to grandparent: Have all test suite entry points declare the mock $region_highlight.
tests/generate.zsh already does this.
2020-07-14 01:57:02 +00:00
Daniel Shahaf
810c2dcede Use the new, unreleased zsh 'memo=' feature to remove only our own entries from $region_highlight.
Fixes #418 (interoperability issue with other plugins).
2020-07-14 00:32:36 +00:00
Daniel Shahaf
f6471dbec3 tests: Fix a wrong value of $PREBUFFER in a test, and add checks to prevent this from recurring.
Discussed: https://github.com/zsh-users/zsh-syntax-highlighting/pull/706#issuecomment-642072978
2020-06-11 08:14:07 +00:00
Daniel Shahaf
f6f7a91818 test harness: Fix use of an undefined variable in an error message.
The error message uses «$1», but it is always unset at that point.
Furthermore, the NO_UNSET (-u) option is in effect.  Therefore, when the
error message was to be printed, zsh's NO_UNSET error message was
printed instead:
.
    (anon):20: 1: parameter not set

That error message was printed to stderr, and was caught by the caller
within the test harness:
.
    Bail out! On './highlighters/main/test-data/path_prefix3.zsh': output on stderr

Thus, the bug being fixed would not caused false positive or false
negative test results, but only wrong error messages.

Follow-up to 0.7.1-71-ge6eea1f, "test harness: Don't leak options from
test files to the test harness".
2020-06-11 08:09:45 +00:00
Daniel Shahaf
d4df626c03 'main': Optimize the unquoted arguments characterwise walker
Fixes #730.

% repeat 3 { zsh -f tests/test-zprof.zsh main | tee … | grep -w _zsh_highlight | head -n1 }
19)    1       26787.11 26787.11  100.00%      5.33     5.33    0.02%  _zsh_highlight
19)    1       26900.64 26900.64  100.00%      5.45     5.45    0.02%  _zsh_highlight
19)    1       26915.76 26915.76  100.00%      5.47     5.47    0.02%  _zsh_highlight

Merge remote-tracking branch 'danielsh/perf-argument-1-v2'

* danielsh/perf-argument-1-v2:
  'main': Further optimize argument parsing.
  'main': Optimize a hot path.
  tests: Add a performance testing script, for measuring the performance of the 'main' highlighter on a large file.
2020-05-22 04:43:04 +00:00
Daniel Shahaf
a50647e77b tests: Add a performance testing script, for measuring the performance of the 'main' highlighter on a large file.
% git co HEAD^ && repeat 3 { zsh -f tests/test-zprof.zsh main | tee … | grep -w _zsh_highlight | head -n1 }
HEAD is now at f1948df tests: Add a performance testing script, for measuring the performance of the 'main' highlighter on a large file.
19)    1       34378.97 34378.97  100.00%      5.43     5.43    0.02%  _zsh_highlight
19)    1       34058.34 34058.34  100.00%      5.50     5.50    0.02%  _zsh_highlight
19)    1       34364.80 34364.80  100.00%      5.36     5.36    0.02%  _zsh_highlight
2020-05-22 04:31:48 +00:00
Daniel Shahaf
4dd4797ae0 test harness: Print the expected-v.-actual on every failure, not just upon cardinality failures.
I was looking into something and wanted to see how a the second word in the
array was highlighted, even though the failure was on the third word.
2020-05-22 03:27:48 +00:00
Daniel Shahaf
343ec1061f 'make perf': Show only a cumulative datum per highligher, rather than per test file.
The overall per-highlighter duration should be less prone to random
noise than the multitude of per-test-file figures.
2020-05-04 17:48:47 +00:00
Daniel Shahaf
2904e0f986 test harness: Fix the pretty-printer's padding implementation.
The new implementation is less efficient but definitely correct.
2020-03-20 00:03:01 +00:00
Daniel Shahaf
d5d2f22013 Revert "test harness: Rewrite the columnar pretty-printer without external tools." and "travis: Remove bsdmainutils since column(1) has been removed, three commits ago."
This reverts commits ea7c165b59 and
3d81c83132.

When "have 6 expectations and 4 region_highlight entries", the pure-zsh
implementation printed them as follows:

    not ok 7 - cardinality check - have 6 expectations and 4 region_highlight entries: «expected_region_highlight=( $'1 1 builtin' $'3 6 comment' $'8 13 comment' $'15 15 default' $'16 21 comment' $'22 22 default' )»
    «region_highlight=( $'0 1 builtin' $'2 6 comment' $'7 13 comment' $'14 22 default' )»
    # expected_region_highlight  '22 22 default'
    # '1 1 builtin'              region_highlight
    # '3 6 comment'              '0 1 builtin'
    # '8 13 comment'             '2 6 comment'
    # '15 15 default'            '7 13 comment'
    # '16 21 comment'            '14 22 default'

Whereas the column(1)-based implementation prints them as follows:

    not ok 7 - cardinality check - have 6 expectations and 4 region_highlight entries: «expected_region_highlight=( $'1 1 builtin' $'3 6 comment' $'8 13 comment' $'15 15 default' $'16 21 comment' $'22 22 default' )» «region_highlight=( $'0 1 builtin' $'2 6 comment' $'7 13 comment' $'14 22 default' )»
    # expected_region_highlight  region_highlight
    # '1 1 builtin'              '0 1 builtin'
    # '3 6 comment'              '2 6 comment'
    # '8 13 comment'             '7 13 comment'
    # '15 15 default'            '14 22 default'
    # '16 21 comment'
    # '22 22 default'

Ultimately, this difference is down to the pure-zsh implementation
getting the arguments as a single list, whereas paste(1) gets two
separate lists.
2020-03-20 00:03:01 +00:00
Daniel Shahaf
9e9885253a test harness: Output the time information to the same place the test name was printed to. 2020-03-19 19:17:41 +00:00
Daniel Shahaf
3e7745ef30 test harness: Stringify values in a more readable manner.
(q-) passes through newlines and NUL bytes verbatim.  Using (qqqq) ensures the
escaped string will be on a single line (as required by the TAP format) and be
readable even if it contains control characters.
2020-03-19 19:15:21 +00:00
Daniel Shahaf
ea7c165b59 test harness: Rewrite the columnar pretty-printer without external tools. 2020-03-19 05:01:54 +00:00
Daniel Shahaf
90a92b2bb8 test harness: Fix an issue with the pretty-printed $expected_region_highlight/$region_highlight diffing.
If the right column was longer, the excess entries were printed on the left column.
2020-03-19 05:01:54 +00:00
Daniel Shahaf
3ff5bec82e test harness: Let tests fail early by exiting non-zero or by setting a flag.
Fixes #609.
2020-03-19 00:37:21 +00:00
Daniel Shahaf
c4bb260a30 test harness: Print the test name when $skip_test is set. 2020-03-19 00:16:09 +00:00
Daniel Shahaf
9bdeb4aa4a test harness: Remove a bogus check.
We already declare $expected_region_highlight in run_test_internal().
Therefore, it will always be declared.
2020-03-19 00:03:24 +00:00
Daniel Shahaf
63852df983 test harness: Fix $skip_test support, broken yesterday.
It was broken by commit e6eea1f9b7,
"test harness: Don't leak options from test files to the test harness.".
2020-03-19 00:00:51 +00:00
Daniel Shahaf
bdb4e8b70e test harness: When the cardinality check fails, pretty-print \$expected_region_highlight and \$region_highlight. 2020-03-17 17:06:32 +00:00
Daniel Shahaf
e6eea1f9b7 test harness: Don't leak options from test files to the test harness.
Fixes an issue whereby the '# TODO "issue #687"' directive in the output of
opt-shwordsplit1.zsh was truncated, because the test itself had set the
SH_WORD_SPLIT option and that affected the evaluation of
«${(z)expected_region_highlight[i]}» in the test harness.

Furthermore, this patch also independently fixes the error under
zsh-5.0.8 and earlier that was fixed by the previous commit.
2020-03-17 16:48:57 +00:00
Daniel Shahaf
99389327ae test harness: Fix test failures under zsh 5.0.8 and older.
The output of test-data/opt-shwordsplit1.zsh on zsh 5.7 is:
.
    1..2
    ## opt-shwordsplit1
    # BUFFER=vim
    not ok 1 - [1,7] «$EDITOR» - expected (1 7 "function"), observed (1 7 "unknown-token"). # TODO "issue
    ok 2 - cardinality check # SKIP cardinality check disabled whilst regular test points are expected to fail

On zsh 5.0.8, tap_escape() choked when called on the arguments argv=('[1,7]'
'«vim»').  This patch fixes that.

As you may have noticed, under zsh 5.7 the diagnostic message of test point 1
is truncated.  That'll be fixed in the next commit.
2020-03-17 16:22:56 +00:00
Daniel Shahaf
61c1cfe99f test harness: Change cardinality check semantics
The cardinality check shall —

- if the test sets \$expected_mismatch, be XFail;
- elif any test points is XFail, be skipped;
- else, be expected to pass.

To test this, change «6 * 9» to «6 + 9» in test-data/arith1.zsh that
will be added in the after-next (grandchild) commit.
2020-03-17 15:05:22 +00:00
Daniel Shahaf
ea2f1060f6 test harness: No-op change to minimize the next diff. 2020-03-17 15:05:22 +00:00
Daniel Shahaf
f63f07417d Merge remote-tracking branch 'danielsh/tests-skip-cardinality-v1'
* danielsh/tests-skip-cardinality-v1:
  tests: Minor documentation readability tweak
  Add a test for issue #641.5, using the infrastructure added in the previous commits.
  tests: Skip cardinality tests whenever any test point is expected to fail.
  tests: Make $expected_mismatch skip the cardinality check, rather than consider it an expected failure.
  tests: Include the name of the 'cardinality check' test point in the output
2020-03-15 18:38:26 +00:00
Daniel Shahaf
37b6f5052f test harness: Update tests/edit-failed-tests for harness output changes in commit 2b3638a211, "test harness: Tweak quiet-test output". 2020-03-15 13:33:09 +00:00
Daniel Shahaf
8e3578240c tests harness docs: Add paragraph breaks. 2020-02-28 22:36:57 +00:00
Daniel Shahaf
027f522300 test harness: Honour $expected_mismatch when there are more expected than observed highlights.
Required for the next commit.
2020-02-28 22:31:43 +00:00
Daniel Shahaf
2b3638a211 test harness: Tweak quiet-test output
- Print the test name and data after the plan line

- Split on the plan line rather than on comments

  + That makes tap-filter more suitable to filter TAP output generated by other
    TAP producers.

  + However, the filtered output deletes the plan line and adds a blank line in
    its stead.  This suits our use-case of interactive test runs.
2020-02-22 15:12:24 +00:00
Daniel Shahaf
3414c7c0d2 test harness: Include $PREBUFFER and $BUFFER in the output.
For human readers' benefit.
2020-02-22 15:12:24 +00:00
Daniel Shahaf
4a043b4d15 noop: Whitespace changes only.
./.editorconfig is already set correctly.
2020-02-22 15:12:24 +00:00
Daniel Shahaf
dc70e89bfd tests: Support non-arrays in typeset_p(). 2020-02-22 15:12:24 +00:00
Daniel Shahaf
deee22ed42 tests: Don't filter out tests that aborted.
Useful in piping Travis CI output through tap-filter manually.
2020-01-24 00:49:51 +00:00
Daniel Shahaf
9ed2a46ed2 dev tools: New script to ease opening $EDITOR on failing tests.
Has room for improvement; for now, I use it with CTRL-W_f.
2020-01-16 17:19:25 +00:00
Daniel Shahaf
1c6a6d92b0 dev tools: Allow specifying preamble code when generating test cases. 2020-01-16 17:19:25 +00:00
Daniel Shahaf
c0ad50e645 dev tools: Fix regression introduced in commit "Print the test data to stdout for convenience.".
tee(1) truncated $fname.  Fortunately, the data that got truncated had just
been `git add`-ed, so no harm was done.
2020-01-11 20:49:12 +00:00
Daniel Shahaf
6f1f595e3e dev tools: Print the test data to stdout for convenience. 2020-01-07 19:59:49 +00:00
Daniel Shahaf
b7592e581d tests: Minor documentation readability tweak 2019-11-10 11:49:47 +00:00
Daniel Shahaf
4952325051 tests: Skip cardinality tests whenever any test point is expected to fail.
When writing an expected-to-fail test case, the cardinality of $region_highlight
at the time the test is written may differ from the cardinality it will have
once the bug is fixed.  For example, with issue #641.5, the current highlighting
is ['nice', 'x=y', 'y', 'ls'] — four elements — but the correct highlighting
would have three elements: ['nice', 'x=y', 'ls'].  There is no point in reporting
a separate test failure for the cardinality check in this case, nor for 'ls' being
highlighted as 'command' rather than 'default'.

At the same time, in other cases the current and correct highlighting may have the
same number of elements (for example, this would be the case for a hypothetical
"the command word is highlighted as an alias rather than a function" bug).  Thus,
the previous commit, q.v..
2019-11-10 11:49:13 +00:00
Daniel Shahaf
d5a4a6e195 tests: Make $expected_mismatch skip the cardinality check, rather
than consider it an expected failure.

With this change, if $expected_region_highlight and $region_highlight
coincidentally have the same number of elements, the test won't be considered
to fail.

This is useful in conjunction with the next commit, q.v..

At this time, no tests set $expected_mismatch explicitly.  However, the
commit after next (this commit's grandchild) will add a test that will
set $expected_mismatch implicitly, using the functionality in the next
commit (this commit's child).
2019-11-10 11:48:40 +00:00
Daniel Shahaf
e209cbe61a tests: Include the name of the 'cardinality check' test point in the output 2019-11-10 11:20:21 +00:00
Sean Wei
4fb570e104
docs: Enable Syntax Highlighting for Code Snippits 2019-01-13 16:12:41 +08:00
Matthew Martin
693757bfd7 tests: Run harness in an anon function to catch global variables
Thanks Daniel for the set -- suggestion.
2019-01-12 00:36:42 -06:00
Matthew Martin
3259fe338d Revert "tests: Run tests in an anon function to catch global variables"
This reverts commit ba2d8fcf76.

Breaks 4.3.12 and .11
2019-01-06 21:38:13 -06:00
Matthew Martin
ba2d8fcf76 tests: Run tests in an anon function to catch global variables
This would have caught #593.
2019-01-06 21:23:46 -06:00
Matthew Martin
9bd38c6fc0 tests: Use root variable for root of the project 2019-01-06 21:21:42 -06:00
Matthew Martin
dddea5d5dd tests: Set harness variables local 2019-01-06 21:18:41 -06:00
Daniel Shahaf
06893a3873 tests: Escape region_highlight and expected_region_highlight in TAP output.
Required for TAP compliance in case the output ever contains '#' or '\n'.
2018-12-29 12:15:34 +00:00
Daniel Shahaf
580ccaebb8 tests: (try to) Fix test failure under zsh<5.3, where 'typeset -p arrayvar''s is two lines long. 2018-12-29 11:57:15 +00:00