Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete collection of syntax highlighting test files #1213

Closed
sharkdp opened this issue Oct 3, 2020 · 48 comments
Closed

Complete collection of syntax highlighting test files #1213

sharkdp opened this issue Oct 3, 2020 · 48 comments

Comments

@sharkdp
Copy link
Owner

sharkdp commented Oct 3, 2020

With all the recent news about Hacktoberfest I thought it would be a good idea to point out good beginner issues that would be actually helpful for bat. In the past years, I have actually experienced Hacktoberfest as a really great event - both as a contributor as well as a maintainer.

As of recently, bat has a set of syntax highlighting regression tests (see #1124 for more details). The main idea is that we have a large collection of test files for each and every language that bat can highlight. This way, we can make sure that we do not run into issues we had in the past where either (1) syntax highlighting for some language is suddenly not working anymore or (2) bat suddenly crashes/panics for some input (due to incompatibilities in the regex flavors in syntect and Sublime Text).

In order to add a new test file, you can follow these steps (let's take "Ruby" as an example):

  1. Make sure that you are running the latest version of bat (master or bat 0.16) and that bat is available on the path.
  2. Find an example Ruby source file or write one yourself. If possible, the file should aim to be "comprehensive" (i.e. include a lot of the possible syntax), but this is not strictly necessary. A simple file is better than none at all. Also, the files shouldn't be gigantic.
  3. Save the file in tests/syntax-tests/source/Ruby (adapt for your language). The file name could be test.rb (adapt extension) but can also be adapted if that is necessary in order for bat to highlight it correctly (e.g. Makefile).
  4. If you have copied the file from somewhere else, please make sure that the file may be copied under the respective license and that the license is compatible with bats license. If it requires attribution, please add a LICENSE.md in the same folder with a text like this:
    The `test.rb` file has been added from [enter source here] under the following license: 
    
    [add license text here]
    
  5. Go to tests/syntax-tests and run the update.sh Bash script. A new file should be generated in the highlighted folder (e.g. highlighted/Ruby/test.rb).
  6. Use cat or bat --language=txt to display the content of this file and make sure that the syntax highlighting looks correct.
  7. git add the new files in the source folder as well as the autogenerated files in the highlighted folder.
  8. Commit and submit a PR! Please reference this issue (Complete collection of syntax highlighting test files #1213).

List of languages / syntaxes:

  • ActionScript
  • Apache Conf
  • AppleScript
  • ARM Assembly
  • AsciiDoc (Asciidoctor)
  • ASP
  • Assembly (x86_64)
  • AWK
  • Batch File
  • BibTeX
  • Bourne Again Shell (bash)
  • C
  • C#
  • C++
  • Cabal
  • Clojure
  • CMake
  • CoffeeScript
  • CpuInfo (/proc/cpuinfo)
  • Crystal
  • CSS
  • CSV
  • D
  • Dart
  • Diff
  • Dockerfile
  • DotENV
  • Elixir
  • Elm
  • Email
  • Erlang
  • F#
  • Fortran
  • Friendly Interactive Shell (fish)
  • fstab
  • Git Attributes
  • Git Config
  • Git Ignore
  • GLSL
  • Go
  • GraphQL
  • Graphviz (DOT)
  • Groovy
  • /etc/group
  • Haskell
  • Highlight non-printables (--show-all)
  • /etc/hosts
  • HTML
  • INI
  • Java
  • Java Server Page (JSP)
  • JavaScript
  • Jinja2
  • JSON
  • jsonnet
  • Julia
  • Kotlin
  • LaTeX
  • Less
  • Lisp
  • Literate Haskell
  • Lua
  • Makefile
  • Manpage
  • Markdown
  • MATLAB
  • MemInfo (/proc/meminfo)
  • NAnt Build File
  • nginx
  • Nim
  • Nix
  • Objective-C
  • Objective-C++
  • OCaml
  • orgmode
  • Pascal
  • /etc/passwd
  • Perl
  • PHP
  • Plain Text
  • PowerShell
  • Protocol Buffer
  • Puppet
  • PureScript
  • Python
  • QML
  • R
  • Rego
  • Regular Expression
  • requirements.txt
  • resolv (/etc/resolv.conf)
  • reStructuredText
  • Robot Framework.
  • Ruby
  • Ruby Haml
  • Ruby on Rails
  • Rust
  • Salt State (SLS)
  • Sass
  • Scala
  • SCSS
  • SML
  • SQL
  • SSH Config
  • SSHD Config
  • Strace
  • Stylus
  • Swift
  • syslog
  • Tcl
  • Terraform
  • TeX
  • Textile
  • TOML
  • TypeScript
  • TypeScriptReact
  • varlink
  • Verilog
  • VimL
  • Vue Component
  • XML
  • YAML

It would be great if we could focus on the syntaxes in sublimehq/Packages first (marked in bold) as this would allow us to merge #1174 without having to worry (too much) about syntax highlighting regressions. Also, most of these are really popular languages, so it makes sense to have them in the test suite.

@adgai19
Copy link
Contributor

adgai19 commented Oct 3, 2020

Can I submit a python file for this issue?

@sharkdp
Copy link
Owner Author

sharkdp commented Oct 3, 2020

Can I submit a python file for this issue?

yes 👍

@joseemds
Copy link
Contributor

joseemds commented Oct 3, 2020

I will submit a elixir file soon :)

@AkshatGadhwal
Copy link
Contributor

i am not able to run bash update.sh it gives me error :
File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'bat'

@dmbaturin
Copy link
Contributor

@AkshatGadhwal @sharkdp I was also thinking about it. I think the script should first try to run a locally built binary from target/ if one is available. I'm not very familiar with Rust workflows yet though.

@caburum
Copy link

caburum commented Oct 4, 2020

I'm also getting an error

Traceback (most recent call last):
  File "create_highlighted_versions.py", line 85, in <module>
    create_highlighted_versions(output_basepath=args.output)
  File "create_highlighted_versions.py", line 35, in create_highlighted_versions
    ["bat"] + BAT_OPTIONS + [source], stderr=subprocess.PIPE, env=env,
  File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.6/subprocess.py", line 423, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'bat': 'bat'

@dmbaturin
Copy link
Contributor

@CCreativeCND The solution is to add the target/debug/ dir to your $PATH, or copy the binary target/debug/bat to somewhere in your $PATH. That's assuming you run cargo build wihout changing any build options (else the target may be something else than debug).

@sharkdp
Copy link
Owner Author

sharkdp commented Oct 4, 2020

FileNotFoundError: [Errno 2] No such file or directory: 'bat': 'bat'

See step 1 of the instructions above: "Make sure that you are running the latest version of bat (preferably master, but the latest release should also work) and that bat is available on the path."

We could probably improve the error message in the Python script.

loganintech added a commit to loganintech/bat that referenced this issue Oct 4, 2020
sharkdp pushed a commit that referenced this issue Oct 24, 2020
This is to contribute to issue #1213.  I took some of the more
complicated servers I am running as examples.  Everything looks to be
correctly highlighted compared to vim's syntax highlighting.
senden9 added a commit to senden9/bat that referenced this issue Oct 24, 2020
senden9 added a commit to senden9/bat that referenced this issue Oct 24, 2020
sharkdp pushed a commit that referenced this issue Oct 24, 2020
dp304 added a commit to dp304/bat that referenced this issue Oct 25, 2020
Part of the work for issue sharkdp#1213.

A short PowerShell script and the corresponding syntax-highlighted output
has been added. The script exhibits many of the peculiarities of the
PowerShell syntax.
sharkdp pushed a commit that referenced this issue Oct 25, 2020
Part of the work for issue #1213.

A short PowerShell script and the corresponding syntax-highlighted output
has been added. The script exhibits many of the peculiarities of the
PowerShell syntax.
@sharkdp
Copy link
Owner Author

sharkdp commented Nov 23, 2020

Thanks to @henil and all of the other contributors, we now have syntax tests up and running for all main syntaxes (marked in bold) from sublimehq/Packages.

What does that mean?

We can now work towards updating sublimehq/Packages to the latest state with much more confidence regarding possible regressions. Unfortunately, syntect, our syntax highlighting engine, is not compatible with the latest format of the Sublime Text syntaxes, that is starting to be used in sublimehq/Packages. We will therefore likely have to maintain our own fork of that repo, that branches off from the currently used state in bat. We can then apply patches that are compatible with syntect/bat and have them checked automatically.

@Keats
Copy link

Keats commented Dec 15, 2020

The zola users would be interested in helping with that fork I think as well. Being stuck on some old syntaxes means we do not get updates (eg await is not highlighted in the st3 branch of the Rust syntax) or bugs (getzola/zola#1241 which might be an issue in syntect actually, not 100% sure).

esensar added a commit to esensar/bat that referenced this issue Dec 27, 2020
Adds a syntax highlighting test for VimL
with source file based on parts of my own configuration
changed to cover as much of syntax as possible.

**NOTES:**
Last line of source (`syntax enable`) does not get highlighted,
since `syntax` keyword is not part of highlighting rules.

Related to sharkdp#1213
esensar added a commit to esensar/bat that referenced this issue Dec 27, 2020
Adds a syntax highlighting test for VimL
with source file based on parts of my own configuration
changed to cover as much of syntax as possible.

**NOTES:**
Last line of source (`syntax enable`) does not get highlighted,
since `syntax` keyword is not part of highlighting rules.

Related to sharkdp#1213
sharkdp pushed a commit that referenced this issue Dec 28, 2020
Adds a syntax highlighting test for VimL
with source file based on parts of my own configuration
changed to cover as much of syntax as possible.

**NOTES:**
Last line of source (`syntax enable`) does not get highlighted,
since `syntax` keyword is not part of highlighting rules.

Related to #1213
@sharkdp sharkdp unpinned this issue Mar 7, 2021
@sharkdp
Copy link
Owner Author

sharkdp commented Jun 1, 2021

Thanks to @mohamed-abdelnour who added the remaining languages in #1668, this can be closed. Thank you to everyone involved!

@sharkdp sharkdp closed this as completed Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests