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.

93 lines
3.2 KiB

пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 9 година
  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 a key of `$ZSH_HIGHLIGHT_STYLES`.
  14. If `$todo` exists, the test point is marked as TODO (the failure of that test
  15. point will not fail the test), and `$todo` is used as the explanation.
  16. If a test sets `$skip_test` to a non-empty string, the test will be skipped
  17. with the provided string as the reason.
  18. If a test sets `unsorted=1` the order of highlights in `$expected_region_highlight`
  19. need not match the order in `$region_highlight`.
  20. **Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but
  21. interprets the indexes differently.
  22. **Note**: Tests are run with `setopt NOUNSET WARN_CREATE_GLOBAL`, so any
  23. variables the test creates must be declared local.
  24. **Isolation**: Each test is run in a separate subshell, so any variables,
  25. aliases, functions, etc., it defines will be visible to the tested code (that
  26. computes `$region_highlight`), but will not affect subsequent tests. The
  27. current working directory of tests is set to a newly-created empty directory,
  28. which is automatically cleaned up after the test exits. For example:
  29. setopt PATH_DIRS
  30. mkdir -p foo/bar
  31. touch foo/bar/testing-issue-228
  32. chmod +x foo/bar/testing-issue-228
  33. path+=( "$PWD"/foo )
  34. BUFFER='bar/testing-issue-228'
  35. expected_region_highlight=(
  36. "1 21 command" # bar/testing-issue-228
  37. )
  38. Writing new tests
  39. -----------------
  40. An experimental tool is available to generate test files:
  41. zsh -f tests/generate.zsh 'ls -x' acme newfile
  42. This generates a `highlighters/acme/test-data/newfile.zsh` test file based on
  43. the current highlighting of the given `$BUFFER` (in this case, `ls -x`).
  44. _This tool is experimental._ Its interface may change. In particular it may
  45. grow ways to set `$PREBUFFER` to inject free-form code into the generated file.
  46. Highlighting test
  47. -----------------
  48. [`test-highlighting.zsh`](tests/test-highlighting.zsh) tests the correctness of
  49. the highlighting. Usage:
  50. zsh test-highlighting.zsh <HIGHLIGHTER NAME>
  51. All tests may be run with
  52. make test
  53. which will run all highlighting tests and report results in [TAP format][TAP].
  54. By default, the results of all tests will be printed; to show only "interesting"
  55. results (tests that failed but were expected to succeed, or vice-versa), run
  56. `make quiet-test` (or `make test QUIET=y`).
  57. [TAP]: http://testanything.org/
  58. Performance test
  59. ----------------
  60. [`test-perfs.zsh`](tests/test-perfs.zsh) measures the time spent doing the
  61. highlighting. Usage:
  62. zsh test-perfs.zsh <HIGHLIGHTER NAME>
  63. All tests may be run with
  64. make perf