From 6f9034622195856280a6469391c52bc42924ec1a Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Wed, 21 May 2014 21:44:52 -0400 Subject: [PATCH] Add test to check tigrc(5) examples for errors This also fixes the errors identified by the test. --- doc/tigrc.5.adoc | 27 ++++++++++++------- test/tigrc/tigrc-manpage-examples-test | 49 ++++++++++++++++++++++++++++++++++ test/tools/libtest.sh | 2 +- 3 files changed, 67 insertions(+), 11 deletions(-) create mode 100755 test/tigrc/tigrc-manpage-examples-test diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index 9067a70..a40403e 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -38,8 +38,9 @@ one of the Git configuration files, which are read by Tig on startup. See 'git-config(1)' for which files to use. The following example show the basic syntax to use for settings, bindings and colors. +// TEST: gitconfig -------------------------------------------------------------------------- -[tig] show-rev-graph = true +[tig] show-changes = true [tig "color"] cursor = yellow red bold [tig "bind"] generic = P parent -------------------------------------------------------------------------- @@ -83,6 +84,7 @@ is: Examples: +// TEST: tigrc -------------------------------------------------------------------------- set commit-order = topo # Order commits topologically set git-colors = no # Do not read Git's color settings. @@ -103,6 +105,7 @@ set blame-view = \ Or in the Git configuration files: +// TEST: gitconfig -------------------------------------------------------------------------- [tig] line-graphics = no # Disable graphics characters @@ -300,6 +303,7 @@ enum value. For example, `file-name` will automatically have its 'display' setting resolve to 'auto'. Examples: +// TEST: tigrc -------------------------------------------------------------------------- # Enable both ID and line numbers in the blame view set blame-view = date:default author:full file-name:auto id:yes,color \ @@ -425,10 +429,10 @@ key map. The syntax is: *bind* 'keymap' 'key' 'action' Examples: - +// TEST: tigrc -------------------------------------------------------------------------- # Add keybinding to quickly jump to the next diff chunk in the stage view -bind stage Enter :/^@@ +bind stage :/^@@ # Disable the default mapping for running git-gc bind generic G none @@ -444,7 +448,7 @@ bind generic ΓΈ @sh -c "printf '%s' %(commit) | pbcopy" -------------------------------------------------------------------------- Or in the Git configuration files: - +// TEST: gitconfig -------------------------------------------------------------------------- [tig "bind"] # 'unbind' the default quit key binding @@ -485,9 +489,9 @@ combos consisting of an initial `Escape` key followed by a normal key value can be bound using `key`. Examples: - +// TEST: tigrc -------------------------------------------------------------------------- -bind main R reload +bind main R refresh bind main next bind main scroll-page-down bind main o options @@ -554,7 +558,7 @@ following variable names, which are substituted before commands are run: |============================================================================= Examples: - +// TEST: tigrc -------------------------------------------------------------------------- # Save save the current commit as a patch file when the user selects a # commit in the main view and presses 'S'. @@ -572,6 +576,7 @@ expansion of environment variables and process control, this can be achieved by using a shell command: .Configure a binding to copy the current commit ID to the clipboard. +// TEST: tigrc -------------------------------------------------------------------------- bind generic I @sh -c "echo -n %(commit) | xclip -selection c" -------------------------------------------------------------------------- @@ -581,6 +586,7 @@ following example entries can be put in either the .gitconfig or .git/config file: .Git configuration which binds Tig keys to Git command aliases. +// TEST: gitconfig -------------------------------------------------------------------------- [alias] gitk-bg = !"gitk HEAD --not $(git rev-parse --remotes) &" @@ -599,6 +605,7 @@ and act similar to commands run via Tig's prompt. Valid internal commands are configuration file options (as described in this document) and pager view commands. Examples: +// TEST: tigrc -------------------------------------------------------------------------- # Reload ~/.tigrc when 'S' is pressed bind generic S :source .tigrc @@ -755,7 +762,7 @@ given as the last parameter. The syntax is: *color* 'area' 'fgcolor' 'bgcolor' '[attributes]' Examples: - +// TEST: tigrc ------------------------------------------------------------------------------ # Override the default terminal colors to white on black. color default white black @@ -769,7 +776,7 @@ color tree.date black cyan bold -------------------------------------------------------------------------- Or in the Git configuration files: - +// TEST: gitconfig -------------------------------------------------------------------------- [tig "color"] # A strange looking cursor line @@ -940,7 +947,7 @@ current configuration file will take precedence. The syntax is: *source* 'path' Examples: - +// TEST: tigrc -------------------------------------------------------------------------- source ~/.tig/colorscheme.tigrc source ~/.tig/keybindings.tigrc diff --git a/test/tigrc/tigrc-manpage-examples-test b/test/tigrc/tigrc-manpage-examples-test new file mode 100755 index 0000000..9566774 --- /dev/null +++ b/test/tigrc/tigrc-manpage-examples-test @@ -0,0 +1,49 @@ +#!/bin/sh + +. libtest.sh + +steps ":quit" + +mkdir snippets + +out_file= + +while read line; do + case "$line" in + "// TEST: tigrc") + out_file="$(mktemp snippets/tigrc.XXXXXX)" + ;; + "// TEST: gitconfig") + out_file="$(mktemp snippets/gitconfig.XXXXXX)" + ;; + "--------------"*) + if [ -s "$out_file" ]; then + out_file= + elif [ -e "$out_file" ]; then + echo >> "$out_file" + fi + ;; + *) + if [ -e "$out_file" ]; then + echo "$line" >> "$out_file" + fi + ;; + esac +done < "$base_dir/../doc/tigrc.5.adoc" + +# Create files used by the `source` example +mkdir .tig +touch .tig/colorscheme.tigrc .tig/keybindings.tigrc + +tigrc <