You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.9 KiB

  1. zsh-syntax-highlighting / tests
  2. ===============================
  3. Utility scripts for testing zsh-syntax-highlighting highlighters.
  4. The tests harness expects the highlighter directory to contain a `test-data`
  5. directory with test data files.
  6. See the [main highlighter](../highlighters/main/test-data) for examples.
  7. Each test should define the string `$BUFFER` that is to be highlighted and the
  8. array parameter `$expected_region_highlight`.
  9. The value of that parameter is a list of strings of the form `"$i $j $style"`.
  10. or `"$i $j $style $todo"`.
  11. Each string specifies the highlighting that `$BUFFER[$i,$j]` should have;
  12. that is, `$i` and `$j` specify a range, 1-indexed, inclusive of both endpoints.
  13. `$style` is either a key of `$ZSH_HIGHLIGHT_STYLES` or `NONE` to specify no
  14. highlighting should be observed.
  15. If `$todo` exists, the test point is marked as TODO (the failure of that test
  16. point will not fail the test), and `$todo` is used as the explanation.
  17. **Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but
  18. interprets the indexes differently.
  19. **Isolation**: Each test is run in a separate subshell, so any variables,
  20. aliases, functions, etc., it defines will be visible to the tested code (that
  21. computes `$region_highlight`), but will not affect subsequent tests. The
  22. current working directory of tests is set to a newly-created empty directory,
  23. which is automatically cleaned up after the test exits. For example:
  24. setopt PATH_DIRS
  25. mkdir -p foo/bar
  26. touch foo/bar/testing-issue-228
  27. chmod +x foo/bar/testing-issue-228
  28. path+=( "$PWD"/foo )
  29. BUFFER='bar/testing-issue-228'
  30. expected_region_highlight=(
  31. "1 21 command" # bar/testing-issue-228
  32. )
  33. Writing new tests
  34. -----------------
  35. An experimental tool is available to generate test files:
  36. zsh -f tests/generate.zsh 'ls -x' acme newfile
  37. This generates a `highlighters/acme/test-data/newfile.zsh` test file based on
  38. the current highlighting of the given `$BUFFER` (in this case, `ls -x`).
  39. _This tool is experimental._ Its interface may change. In particular it may
  40. grow ways to set `$PREBUFFER` to inject free-form code into the generated file.
  41. Highlighting test
  42. -----------------
  43. [`test-highlighting.zsh`](tests/test-highlighting.zsh) tests the correctness of
  44. the highlighting. Usage:
  45. zsh test-highlighting.zsh <HIGHLIGHTER NAME>
  46. All tests may be run with
  47. make test
  48. which will run all highlighting tests and report results in [TAP format][TAP].
  49. By default, the results of all tests will be printed; to show only "interesting"
  50. results (tests that failed but were expected to succeed, or vice-versa), run
  51. `make quiet-test` (or `make test QUIET=y`).
  52. [TAP]: http://testanything.org/
  53. Performance test
  54. ----------------
  55. [`test-perfs.zsh`](tests/test-perfs.zsh) measures the time spent doing the
  56. highlighting. Usage:
  57. zsh test-perfs.zsh <HIGHLIGHTER NAME>
  58. All tests may be run with
  59. make perf