[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 2e87bd4c01a56e9752b24e15c82ffd4e9f7634a3

Freddy Vulto fvulto at gmail.com
Wed Aug 12 20:22:01 UTC 2009


The following commit has been merged in the master branch:
commit 2e87bd4c01a56e9752b24e15c82ffd4e9f7634a3
Author: Freddy Vulto <fvulto at gmail.com>
Date:   Wed Aug 12 22:20:56 2009 +0200

    Added setting COMP_KNOWN_HOSTS_WITH_HOSTFILE
    `_known_hosts_real' will add hosts from HOSTFILE (compgen -A hostname), unless
    `COMP_KNOWN_HOSTS_WITH_HOSTFILE' is set to an empty value.
    
    To run the unit tests:
    
       $ cd test && ./runUnit _known_hosts_real.exp

diff --git a/CHANGES b/CHANGES
index 620fa6f..7de6a60 100644
--- a/CHANGES
+++ b/CHANGES
@@ -143,6 +143,9 @@ bash-completion (1.x)
   * Patched _known_hosts() to support multiple {Global,User}KnownHosts in SSH
     config files, thanks to Thomas Nilsson (Alioth: #311595) (Debian: #524190)
   * Fix leaking $i from info, man and python completions.
+  * Added setting COMP_KNOWN_HOSTS_WITH_HOSTFILE. _known_hosts_real() will add
+    hosts from HOSTFILE, unless COMP_KNOWN_HOSTS_WITH_HOSTFILE is set to an
+    empty value (Alioth: #311821)
 
  -- David Paleino <d.paleino at gmail.com>  Thu, 18 Jun 2009 13:12:36 +0200
 
diff --git a/bash_completion b/bash_completion
index ef34510..ec4e070 100644
--- a/bash_completion
+++ b/bash_completion
@@ -1214,16 +1214,16 @@ _known_hosts_real()
 			fi
 		fi
 
-		# Now add results of normal hostname completion
-		COMPREPLY=( "${COMPREPLY[@]}" $( compgen -A hostname -- $cur ) )
-
 		# apply suffix and prefix
 		for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
 			COMPREPLY[i]=$prefix$user${COMPREPLY[i]}$suffix
 		done
-	elif [ -z "$configfile" ]; then
-	    # Just do normal hostname completion
-	    COMPREPLY=( $( compgen -A hostname -S "$suffix" -- $cur ) )
+	fi
+
+	# Add results of normal hostname completion, unless `COMP_KNOWN_HOSTS_WITH_HOSTFILE'
+	# is set to an empty value.
+	if [ -n "${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1}" ]; then
+		COMPREPLY=( "${COMPREPLY[@]}" $( compgen -A hostname -P "$prefix$user" -S "$suffix" -- $cur ) )
 	fi
 
 	return 0
diff --git a/doc/bash_completion.txt b/doc/bash_completion.txt
new file mode 100644
index 0000000..c7e7a2b
--- /dev/null
+++ b/doc/bash_completion.txt
@@ -0,0 +1,34 @@
+Bash completion
+===============
+
+Environment variables
+---------------------
+
+*COMP_CONFIGURE_HINTS*::
+    If set and not null, `configure` completion will return the entire option
+    string (e.g.  `--this-option=DESCRIPTION`) so one can see what kind of data
+    is required and then simply delete the descriptive text and add one's own
+    data.  If unset or null (default), `configure` completion will strip
+    everything after the '=' when returning completions.
+
+
+*COMP_CVS_REMOTE*::
+    If set and not null, `cvs commit` completion will try to complete on
+    remotely checked-out files.  This requires passwordless access to the
+    remote repository.  Default is unset.
+
+
+*COMP_KNOWN_HOSTS_WITH_HOSTFILE*::
+    If set and not null (default), known_hosts completion will complement
+    hostnames from ssh's known_hosts_files with hostnames taken from the file
+    specified by the HOSTFILE shell variable (compgen -A hostname). If null,
+    known_hosts completion will omit hostnames from HOSTFILE.  Omitting
+    hostnames from HOSTFILE is useful if HOSTFILE contains many entries for
+    local web development or ad-blocking.
+
+
+*COMP_TAR_INTERNAL_PATHS*::
+    If set and not null *before* sourcing bash_completion, `tar` completion
+    will do correct path completion for tar file contents.  If unset or null,
+    `tar' completion will do correct completion for paths to tar files.  See
+    also README.
diff --git a/doc/html~/main.html b/doc/html~/main.html
index adbd0c5..86ce6d8 100644
--- a/doc/html~/main.html
+++ b/doc/html~/main.html
@@ -1,9 +1,39 @@
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Bash-completion</title><link rel="stylesheet" href="./docbook-xsl.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /></head><body><div class="book" lang="en" xml:lang="en"><div class="titlepage"><div><div><h1 class="title"><a id="id2579299"></a>Bash-completion</h1></div><div><div class="author"><h3 class="author"><span class="firstname">Freddy</span> <span class="othername">Vulto</span> <span class="surname">(FVu)</span></h3></div></div><div><div class="revhistory"><table border="1" width="100%" summary="Revision history"><tr><th align="left" valign="top" colspan="3"><b>Revision History</b></th></tr><tr><td align="left">Revision 1.0</td><td align="left">Mar 2009</td><td align="left">FV(</td></tr></table></div></div></div><hr /></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="preface"><a href="#_preface">Preface</a></span></dt><dt><span class="part"><a href="#_coding_style_guide">I. Coding Style Guide</a></span></dt><dd><dl><dt><span class="chapter"><a href="#_introduction">1. Introduction</a></span></dt></dl></dd><dt><span class="part"><a href="#_automated_testing">II. Automated testing</a></span></dt><dd><dl><dt><span class="chapter"><a href="#_introduction_2">2. Introduction</a></span></dt><dt><span class="chapter"><a href="#_installing_dejagnu">3. Installing DejaGnu</a></span></dt><dd><dl><dt><span class="section"><a href="#_debian_ubuntu">3.1. Debian/Ubuntu</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_structure">4. Structure</a></span></dt><dd><dl><dt><span class="section"><a href="#_main_areas_dejagnu_tools">4.1. Main areas (DejaGnu tools)</a></span></dt><dt><span class="section"><a href="#_running_the_tests">4.2. Running the tests</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_maintenance">5. Maintenance</a></span></dt><dd><dl><dt><span class="section"><a href="#_adding_a_completion_test">5.1. Adding a completion test</a></span></dt><dt><span class="section"><a href="#_fixing_a_completion_test">5.2. Fixing a completion test</a></span></dt><dt><span class="section"><a href="#_fixing_a_unit_test">5.3. Fixing a unit test</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_rationale">6. Rationale</a></span></dt><dd><dl><dt><span class="section"><a href="#_naming_conventions">6.1. Naming conventions</a></span></dt><dd><dl><dt><span class="section"><a href="#_test_suite_or_testsuite">6.1.1. Test suite or testsuite</a></span></dt><dt><span class="section"><a href="#_script_generate">6.1.2. script/generate</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#_reference">7. Reference</a></span></dt><dt><span class="chapter"><a href="#Test_context">8. Test context</a></span></dt><dd><dl><dt><span class="section"><a href="#_what_happens_when_tests_are_run">8.1. What happens when tests are run?</a></span></dt><dd><dl><dt><span class="section"><a href="#_completion">8.1.1. completion</a></span></dt><dt><span class="section"><a href="#_install">8.1.2. install</a></span></dt><dt><span class="section"><a href="#_unit">8.1.3. unit</a></span></dt></dl></dd><dt><span class="section"><a href="#_bashrc">8.2. bashrc</a></span></dt><dt><span class="section"><a href="#_inputrc">8.3. inputrc</a></span></dt></dl></dd></dl></dd><dt><span class="index"><a href="#_index">Index</a></span></dt></dl></div><div class="list-of-examples"><p><b>List of Examples</b></p><dl><dt>8.1. <a href="#id2682547">What happens when completion tests are run?</a></dt><dt>8.2. <a href="#id2682611">What happens when install tests are run?</a></dt><dt>8.3. <a href="#id2682641">What happens when unit tests are run?</a></dt></dl></div><div class="preface" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_preface"></a>Preface</h2></div></div></div><p>Bash completion extends bashs standard completion behavior to achieve
+<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Bash-completion</title><link rel="stylesheet" href="./docbook-xsl.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /></head><body><div class="book" lang="en" xml:lang="en"><div class="titlepage"><div><div><h1 class="title"><a id="id2603628"></a>Bash-completion</h1></div><div><div class="author"><h3 class="author"><span class="firstname">Freddy</span> <span class="othername">Vulto</span> <span class="surname">(FVu)</span></h3></div></div><div><div class="revhistory"><table border="1" width="100%" summary="Revision history"><tr><th align="left" valign="top" colspan="3"><b>Revision History</b></th></tr><tr><td align="left">Revision 1.0</td><td align="left">Mar 2009</td><td align="left">FV(</td></tr></table></div></div></div><hr /></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="preface"><a href="#_preface">Preface</a></span></dt><dt><span class="part"><a href="#_bash_completion">I. Bash completion</a></span></dt><dd><dl><dt><span class="chapter"><a href="#_environment_variables">1. Environment variables</a></span></dt></dl></dd><dt><span class="part"><a href="#_coding_style_guide">II. Coding Style Guide</a></span></dt><dd><dl><dt><span class="chapter"><a href="#_introduction">2. Introduction</a></span></dt></dl></dd><dt><span class="part"><a href="#_automated_testing">III. Automated testing</a></span></dt><dd><dl><dt><span class="chapter"><a href="#_introduction_2">3. Introduction</a></span></dt><dt><span class="chapter"><a href="#_installing_dejagnu">4. Installing DejaGnu</a></span></dt><dd><dl><dt><span class="section"><a href="#_debian_ubuntu">4.1. Debian/Ubuntu</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_structure">5. Structure</a></span></dt><dd><dl><dt><span class="section"><a href="#_main_areas_dejagnu_tools">5.1. Main areas (DejaGnu tools)</a></span></dt><dt><span class="section"><a href="#_running_the_tests">5.2. Running the tests</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_maintenance">6. Maintenance</a></span></dt><dd><dl><dt><span class="section"><a href="#_adding_a_completion_test">6.1. Adding a completion test</a></span></dt><dt><span class="section"><a href="#_fixing_a_completion_test">6.2. Fixing a completion test</a></span></dt><dt><span class="section"><a href="#_fixing_a_unit_test">6.3. Fixing a unit test</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_rationale">7. Rationale</a></span></dt><dd><dl><dt><span class="section"><a href="#_naming_conventions">7.1. Naming conventions</a></span></dt><dd><dl><dt><span class="section"><a href="#_test_suite_or_testsuite">7.1.1. Test suite or testsuite</a></span></dt><dt><span class="section"><a href="#_script_generate">7.1.2. script/generate</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#_reference">8. Reference</a></span></dt><dt><span class="chapter"><a href="#Test_context">9. Test context</a></span></dt><dd><dl><dt><span class="section"><a href="#_what_happens_when_tests_are_run">9.1. What happens when tests are run?</a></span></dt><dd><dl><dt><span class="section"><a href="#_completion">9.1.1. completion</a></span></dt><dt><span class="section"><a href="#_install">9.1.2. install</a></span></dt><dt><span class="section"><a href="#_unit">9.1.3. unit</a></span></dt></dl></dd><dt><span class="section"><a href="#_bashrc">9.2. bashrc</a></span></dt><dt><span class="section"><a href="#_inputrc">9.3. inputrc</a></span></dt></dl></dd></dl></dd><dt><span class="index"><a href="#_index">Index</a></span></dt></dl></div><div class="list-of-examples"><p><b>List of Examples</b></p><dl><dt>9.1. <a href="#id2644163">What happens when completion tests are run?</a></dt><dt>9.2. <a href="#id2646974">What happens when install tests are run?</a></dt><dt>9.3. <a href="#id2636096">What happens when unit tests are run?</a></dt></dl></div><div class="preface" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_preface"></a>Preface</h2></div></div></div><p>Bash completion extends bashs standard completion behavior to achieve
 complex command lines with just a few keystrokes.  This project was
 conceived to produce programmable completion routines for the most
 common Linux/UNIX commands, reducing the amount of typing sysadmins
-and programmers need to do on a daily basis.</p></div><div class="part" lang="en" xml:lang="en"><div class="titlepage"><div><div><h1 class="title"><a id="_coding_style_guide"></a>Part I. Coding Style Guide</h1></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="chapter"><a href="#_introduction">1. Introduction</a></span></dt></dl></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_introduction"></a>Chapter 1. Introduction</h2></div></div></div><p>This document attempts to explain the basic styles and patterns that are used in the bash completion.  New code should try to conform to these standards so that it is as easy to maintain as existing code.  Of course every rule has an exception, but it's important to know the rules nonetheless!</p><p>This is particularly directed at people new to the bash completion codebase, who are in the process of getting their code reviewed.  Before getting a review, please read over this document and make sure your code conforms to the recommendations here.</p></div></div><div class="part" lang="en" xml:lang="en"><div class="titlepage"><div><div><h1 class="title"><a id="_automated_testing"></a>Part II. Automated testing</h1></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="chapter"><a href="#_introduction_2">2. Introduction</a></span></dt><dt><span class="chapter"><a href="#_installing_dejagnu">3. Installing DejaGnu</a></span></dt><dd><dl><dt><span class="section"><a href="#_debian_ubuntu">3.1. Debian/Ubuntu</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_structure">4. Structure</a></span></dt><dd><dl><dt><span class="section"><a href="#_main_areas_dejagnu_tools">4.1. Main areas (DejaGnu tools)</a></span></dt><dt><span class="section"><a href="#_running_the_tests">4.2. Running the tests</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_maintenance">5. Maintenance</a></span></dt><dd><dl><dt><span class="section"><a href="#_adding_a_completion_test">5.1. Adding a completion test</a></span></dt><dt><span class="section"><a href="#_fixing_a_completion_test">5.2. Fixing a completion test</a></span></dt><dt><span class="section"><a href="#_fixing_a_unit_test">5.3. Fixing a unit test</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_rationale">6. Rationale</a></span></dt><dd><dl><dt><span class="section"><a href="#_naming_conventions">6.1. Naming conventions</a></span></dt><dd><dl><dt><span class="section"><a href="#_test_suite_or_testsuite">6.1.1. Test suite or testsuite</a></span></dt><dt><span class="section"><a href="#_script_generate">6.1.2. script/generate</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#_reference">7. Reference</a></span></dt><dt><span class="chapter"><a href="#Test_context">8. Test context</a></span></dt><dd><dl><dt><span class="section"><a href="#_what_happens_when_tests_are_run">8.1. What happens when tests are run?</a></span></dt><dd><dl><dt><span class="section"><a href="#_completion">8.1.1. completion</a></span></dt><dt><span class="section"><a href="#_install">8.1.2. install</a></span></dt><dt><span class="section"><a href="#_unit">8.1.3. unit</a></span></dt></dl></dd><dt><span class="section"><a href="#_bashrc">8.2. bashrc</a></span></dt><dt><span class="section"><a href="#_inputrc">8.3. inputrc</a></span></dt></dl></dd></dl></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_introduction_2"></a>Chapter 2. Introduction</h2></div></div></div><p>The bash-completion package contains an automated test suite.  Running the tests should help verifying that bash-completion works as expected.  The tests are also very helpful in uncovering software regressions at an early stage.</p><p>The bash-completion test suite is written on top of the <a class="ulink" href="http://www.gnu.org/software/dejagnu/" target="_top">DejaGnu</a> testing framework.  DejaGnu is written in <a class="ulink" href="http://expect.nist.gov" target="_top">Expect</a>, which in turn uses <a class="ulink" href="http://tcl.sourceforge.net" target="_top">Tcl</a> — Tool command language.</p></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_installing_dejagnu"></a>Chapter 3. Installing DejaGnu</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#_debian_ubuntu">3.1. Debian/Ubuntu</a></span></dt></dl></div><p>Installing DejaGnu should be easy using your local package manager.</p><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_debian_ubuntu"></a>3.1. Debian/Ubuntu</h2></div></div></div><p>On Debian/Ubuntu you can use <code class="literal">apt-get</code>:</p><pre class="screen">sudo apt-get install dejagnu</pre><p>This should also install the necessary <code class="literal">expect</code> and <code class="literal">tcl</code> packages.</p></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_structure"></a>Chapter 4. Structure</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#_main_areas_dejagnu_tools">4.1. Main areas (DejaGnu tools)</a></span></dt><dt><span class="section"><a href="#_running_the_tests">4.2. Running the tests</a></span></dt></dl></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_main_areas_dejagnu_tools"></a>4.1. Main areas (DejaGnu tools)</h2></div></div></div><p>The tests are grouped into different areas, called <span class="emphasis"><em>tool</em></span> in DejaGnu:</p><div class="variablelist"><dl><dt><span class="term">
+and programmers need to do on a daily basis.</p></div><div class="part" lang="en" xml:lang="en"><div class="titlepage"><div><div><h1 class="title"><a id="_bash_completion"></a>Part I. Bash completion</h1></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="chapter"><a href="#_environment_variables">1. Environment variables</a></span></dt></dl></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_environment_variables"></a>Chapter 1. Environment variables</h2></div></div></div><div class="variablelist"><dl><dt><span class="term">
+<span class="strong"><strong>COMP_CONFIGURE_HINTS</strong></span>
+</span></dt><dd>
+    If set and not null, <code class="literal">configure</code> completion will return the entire option
+    string (e.g.  <code class="literal">--this-option=DESCRIPTION</code>) so one can see what kind of data
+    is required and then simply delete the descriptive text and add one’s own
+    data.  If unset or null (default), <code class="literal">configure</code> completion will strip
+    everything after the <span class="emphasis"><em>=</em></span> when returning completions.
+</dd><dt><span class="term">
+<span class="strong"><strong>COMP_CVS_REMOTE</strong></span>
+</span></dt><dd>
+    If set and not null, <code class="literal">cvs commit</code> completion will try to complete on
+    remotely checked-out files.  This requires passwordless access to the
+    remote repository.  Default is unset.
+</dd><dt><span class="term">
+<span class="strong"><strong>COMP_KNOWN_HOSTS_WITH_HOSTFILE</strong></span>
+</span></dt><dd>
+    If set and not null (default), known_hosts completion will complement
+    hostnames from ssh’s known_hosts_files with hostnames taken from the file
+    specified by the HOSTFILE shell variable (compgen -A hostname). If null,
+    known_hosts completion will omit hostnames from HOSTFILE.  Omitting
+    hostnames from HOSTFILE is useful if HOSTFILE contains many entries for
+    local web development or ad-blocking.
+</dd><dt><span class="term">
+<span class="strong"><strong>COMP_TAR_INTERNAL_PATHS</strong></span>
+</span></dt><dd>
+    If set and not null <span class="strong"><strong>before</strong></span> sourcing bash_completion, ‘tar` completion
+    will do correct path completion for tar file contents.  If unset or null,
+    `tar’ completion will do correct completion for paths to tar files.  See
+    also README.
+</dd></dl></div></div></div><div class="part" lang="en" xml:lang="en"><div class="titlepage"><div><div><h1 class="title"><a id="_coding_style_guide"></a>Part II. Coding Style Guide</h1></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="chapter"><a href="#_introduction">2. Introduction</a></span></dt></dl></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_introduction"></a>Chapter 2. Introduction</h2></div></div></div><p>This document attempts to explain the basic styles and patterns that are used in the bash completion.  New code should try to conform to these standards so that it is as easy to maintain as existing code.  Of course every rule has an exception, but it’s important to know the rules nonetheless!</p><p>This is particularly directed at people new to the bash completion codebase, who are in the process of getting their code reviewed.  Before getting a review, please read over this document and make sure your code conforms to the recommendations here.</p></div></div><div class="part" lang="en" xml:lang="en"><div class="titlepage"><div><div><h1 class="title"><a id="_automated_testing"></a>Part III. Automated testing</h1></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="chapter"><a href="#_introduction_2">3. Introduction</a></span></dt><dt><span class="chapter"><a href="#_installing_dejagnu">4. Installing DejaGnu</a></span></dt><dd><dl><dt><span class="section"><a href="#_debian_ubuntu">4.1. Debian/Ubuntu</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_structure">5. Structure</a></span></dt><dd><dl><dt><span class="section"><a href="#_main_areas_dejagnu_tools">5.1. Main areas (DejaGnu tools)</a></span></dt><dt><span class="section"><a href="#_running_the_tests">5.2. Running the tests</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_maintenance">6. Maintenance</a></span></dt><dd><dl><dt><span class="section"><a href="#_adding_a_completion_test">6.1. Adding a completion test</a></span></dt><dt><span class="section"><a href="#_fixing_a_completion_test">6.2. Fixing a completion test</a></span></dt><dt><span class="section"><a href="#_fixing_a_unit_test">6.3. Fixing a unit test</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_rationale">7. Rationale</a></span></dt><dd><dl><dt><span class="section"><a href="#_naming_conventions">7.1. Naming conventions</a></span></dt><dd><dl><dt><span class="section"><a href="#_test_suite_or_testsuite">7.1.1. Test suite or testsuite</a></span></dt><dt><span class="section"><a href="#_script_generate">7.1.2. script/generate</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#_reference">8. Reference</a></span></dt><dt><span class="chapter"><a href="#Test_context">9. Test context</a></span></dt><dd><dl><dt><span class="section"><a href="#_what_happens_when_tests_are_run">9.1. What happens when tests are run?</a></span></dt><dd><dl><dt><span class="section"><a href="#_completion">9.1.1. completion</a></span></dt><dt><span class="section"><a href="#_install">9.1.2. install</a></span></dt><dt><span class="section"><a href="#_unit">9.1.3. unit</a></span></dt></dl></dd><dt><span class="section"><a href="#_bashrc">9.2. bashrc</a></span></dt><dt><span class="section"><a href="#_inputrc">9.3. inputrc</a></span></dt></dl></dd></dl></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_introduction_2"></a>Chapter 3. Introduction</h2></div></div></div><p>The bash-completion package contains an automated test suite.  Running the tests should help verifying that bash-completion works as expected.  The tests are also very helpful in uncovering software regressions at an early stage.</p><p>The bash-completion test suite is written on top of the <a class="ulink" href="http://www.gnu.org/software/dejagnu/" target="_top">DejaGnu</a> testing framework.  DejaGnu is written in <a class="ulink" href="http://expect.nist.gov" target="_top">Expect</a>, which in turn uses <a class="ulink" href="http://tcl.sourceforge.net" target="_top">Tcl</a> — Tool command language.</p></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_installing_dejagnu"></a>Chapter 4. Installing DejaGnu</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#_debian_ubuntu">4.1. Debian/Ubuntu</a></span></dt></dl></div><p>Installing DejaGnu should be easy using your local package manager.</p><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_debian_ubuntu"></a>4.1. Debian/Ubuntu</h2></div></div></div><p>On Debian/Ubuntu you can use <code class="literal">apt-get</code>:</p><pre class="screen">sudo apt-get install dejagnu</pre><p>This should also install the necessary <code class="literal">expect</code> and <code class="literal">tcl</code> packages.</p></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_structure"></a>Chapter 5. Structure</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#_main_areas_dejagnu_tools">5.1. Main areas (DejaGnu tools)</a></span></dt><dt><span class="section"><a href="#_running_the_tests">5.2. Running the tests</a></span></dt></dl></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_main_areas_dejagnu_tools"></a>5.1. Main areas (DejaGnu tools)</h2></div></div></div><p>The tests are grouped into different areas, called <span class="emphasis"><em>tool</em></span> in DejaGnu:</p><div class="variablelist"><dl><dt><span class="term">
 <span class="strong"><strong>completion</strong></span>
 </span></dt><dd>
   Functional tests per completion.
@@ -15,11 +45,11 @@ and programmers need to do on a daily basis.</p></div><div class="part" lang="en
 <span class="strong"><strong>unit</strong></span>
 </span></dt><dd>
   Unit tests for bash-completion helper functions.
-</dd></dl></div><p>Each tool has a slightly different way of loading the test fixtures, see <a class="link" href="#Test_context" title="Chapter&#xA0;8.&#xA0;Test context">Test context</a> below.</p></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_running_the_tests"></a>4.2. Running the tests</h2></div></div></div><p>The tests are run by calling <code class="literal">runtest</code> in the test directory:</p><pre class="screen">runtest --outdir log --tool completion
+</dd></dl></div><p>Each tool has a slightly different way of loading the test fixtures, see <a class="link" href="#Test_context" title="Chapter&#xA0;9.&#xA0;Test context">Test context</a> below.</p></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_running_the_tests"></a>5.2. Running the tests</h2></div></div></div><p>The tests are run by calling <code class="literal">runtest</code> in the test directory:</p><pre class="screen">runtest --outdir log --tool completion
 runtest --outdir log --tool install
 runtest --outdir log --tool unit</pre><p>The commands above are already wrapped up in shell scripts within the <code class="literal">test</code> directory:</p><pre class="screen">./runCompletion
 ./runInstall
-./runUnit</pre></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_maintenance"></a>Chapter 5. Maintenance</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#_adding_a_completion_test">5.1. Adding a completion test</a></span></dt><dt><span class="section"><a href="#_fixing_a_completion_test">5.2. Fixing a completion test</a></span></dt><dt><span class="section"><a href="#_fixing_a_unit_test">5.3. Fixing a unit test</a></span></dt></dl></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_adding_a_completion_test"></a>5.1. Adding a completion test</h2></div></div></div><p>You can add script/generate to add a test.</p></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_fixing_a_completion_test"></a>5.2. Fixing a completion test</h2></div></div></div><p>Let's consider this real-life example where an ssh completion bug is fixed.  First you're triggered by unsuccessful tests:</p><pre class="screen">$ ./runCompletion
+./runUnit</pre></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_maintenance"></a>Chapter 6. Maintenance</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#_adding_a_completion_test">6.1. Adding a completion test</a></span></dt><dt><span class="section"><a href="#_fixing_a_completion_test">6.2. Fixing a completion test</a></span></dt><dt><span class="section"><a href="#_fixing_a_unit_test">6.3. Fixing a unit test</a></span></dt></dl></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_adding_a_completion_test"></a>6.1. Adding a completion test</h2></div></div></div><p>You can run <code class="literal">cd test &amp;&amp; ./generate</code> to add a test.</p></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_fixing_a_completion_test"></a>6.2. Fixing a completion test</h2></div></div></div><p>Let’s consider this real-life example where an ssh completion bug is fixed.  First you’re triggered by unsuccessful tests:</p><pre class="screen">$ ./runCompletion
 ...
                 === completion Summary ===
 
@@ -28,41 +58,41 @@ runtest --outdir log --tool unit</pre><p>The commands above are already wrapped
 # of unresolved testcases       2
 # of unsupported tests          47</pre><p>Take a look in <code class="literal">log/completion.log</code> to find out which specific command is failing.</p><pre class="screen">$ vi log/completion.log</pre><p>Search for <code class="literal">UNRESOLVED</code> or <code class="literal">FAIL</code>.  From there scroll up to see which <code class="literal">.exp</code> test is failing:</p><pre class="screen">/@Running ./completion/ssh.exp ...
 ...
-UNRESOLVED: Tab should complete ssh known-hosts at prompt</pre><p>In this case it appears <code class="literal">ssh.exp</code> is causing the problem.  Isolate the <code class="literal">ssh</code> tests by specifying just <code class="literal">ssh.exp</code> to run.  Furthermore add the <code class="literal">—debug</code> flag, so output gets logged in <code class="literal">dbg.log</code>:</p><pre class="screen">$ ./runCompletion ssh.exp --debug
+UNRESOLVED: Tab should complete ssh known-hosts at prompt</pre><p>In this case it appears <code class="literal">ssh.exp</code> is causing the problem.  Isolate the <code class="literal">ssh</code> tests by specifying just <code class="literal">ssh.exp</code> to run.  Furthermore add the <code class="literal">--debug</code> flag, so output gets logged in <code class="literal">dbg.log</code>:</p><pre class="screen">$ ./runCompletion ssh.exp --debug
 ...
                 === completion Summary ===
 
 # of expected passes            1
-# of unresolved testcases       1</pre><p>Now we can have a detailed look in <code class="literal">dbg.log</code> to find out what's going wrong.  Open <code class="literal">dbg.log</code> and search for <code class="literal">UNRESOLVED</code> (or <code class="literal">FAIL</code> if that's what you're looking for):</p><pre class="screen">UNRESOLVED: Tab should complete ssh known-hosts at prompt</pre><p>From there, search up for the first line saying:</p><pre class="screen">expect: does "..." match regular expression "..."</pre><p>This tells you where the actual output differs from the expected output.  In this case it looks like the test "ssh -F fixtures/ssh/config &lt;TAB&gt;" is expecting just hostnames, whereas the actual completion is containing commands - but no hostnames.
-So what should be expected after "ssh -F fixtures/ssh/config &lt;TAB&gt;" are <span class="strong"><strong>both</strong></span> commands and hostnames.  This means both the test and the completion need fixing.  Let's start with the test.</p><pre class="screen">$ vi lib/completions/ssh.exp</pre><p>Search for the test "Tab should complete ssh known-hosts".  Here you could've seen that what was expected were hostnames ($hosts):</p><pre class="screen">set expected "^$cmd\r\n$hosts\r\n/@$cmd$"</pre><p>Adding <span class="strong"><strong>all</strong></span> commands (which could well be over 2000) to <span class="emphasis"><em>expected</em></span>, seems a bit overdone so we're gonna change things here.  Lets expect the unit test for <code class="literal">_known_hosts</code> assures all hosts are returned.  Then all we need to do here is expect one host and one command, just to be kind of sure that both hosts and commands are completed.</p><p>Looking in the fixture for ssh:</p><pre class="screen">$ vi fixtures/ssh/known_hosts</pre><p>it looks like we can add an additional host <span class="emphasis"><em>ls_known_host</em></span>.  Now if we would perform the test "ssh -F fixtures/ssh/config ls&lt;TAB&gt;" both the command <code class="literal">ls</code> and the host <code class="literal">ls_known_host</code> should come up.  Let's modify the test so:</p><pre class="screen">$ vi lib/completions/ssh.exp
+# of unresolved testcases       1</pre><p>Now we can have a detailed look in <code class="literal">dbg.log</code> to find out what’s going wrong.  Open <code class="literal">dbg.log</code> and search for <code class="literal">UNRESOLVED</code> (or <code class="literal">FAIL</code> if that’s what you’re looking for):</p><pre class="screen">UNRESOLVED: Tab should complete ssh known-hosts at prompt</pre><p>From there, search up for the first line saying:</p><pre class="screen">expect: does "..." match regular expression "..."</pre><p>This tells you where the actual output differs from the expected output.  In this case it looks like the test "ssh -F fixtures/ssh/config &lt;TAB&gt;" is expecting just hostnames, whereas the actual completion is containing commands - but no hostnames.
+So what should be expected after "ssh -F fixtures/ssh/config &lt;TAB&gt;" are <span class="strong"><strong>both</strong></span> commands and hostnames.  This means both the test and the completion need fixing.  Let’s start with the test.</p><pre class="screen">$ vi lib/completions/ssh.exp</pre><p>Search for the test "Tab should complete ssh known-hosts".  Here you could’ve seen that what was expected were hostnames ($hosts):</p><pre class="screen">set expected "^$cmd\r\n$hosts\r\n/@$cmd$"</pre><p>Adding <span class="strong"><strong>all</strong></span> commands (which could well be over 2000) to <span class="emphasis"><em>expected</em></span>, seems a bit overdone so we’re gonna change things here.  Lets expect the unit test for <code class="literal">_known_hosts</code> assures all hosts are returned.  Then all we need to do here is expect one host and one command, just to be kind of sure that both hosts and commands are completed.</p><p>Looking in the fixture for ssh:</p><pre class="screen">$ vi fixtures/ssh/known_hosts</pre><p>it looks like we can add an additional host <span class="emphasis"><em>ls_known_host</em></span>.  Now if we would perform the test "ssh -F fixtures/ssh/config ls&lt;TAB&gt;" both the command <code class="literal">ls</code> and the host <code class="literal">ls_known_host</code> should come up.  Let’s modify the test so:</p><pre class="screen">$ vi lib/completions/ssh.exp
 ...
 set expected "^$cmd\r\n.*ls.*ls_known_host.*\r\n/@$cmd$"</pre><p>Running the test reveals we still have an unresolved test:</p><pre class="screen">$ ./runCompletion ssh.exp --debug
 ...
                 === completion Summary ===
 
 # of expected passes            1
-# of unresolved testcases       1</pre><p>But if now look into the log file <code class="literal">dbg.log</code> we can see the completion only returns commands starting with <span class="emphasis"><em>ls</em></span> but fails to match our regular expression which also expects the hostname `ls_known_host':</p><pre class="screen">$ vi dbg.log
+# of unresolved testcases       1</pre><p>But if now look into the log file ‘dbg.log` we can see the completion only returns commands starting with <span class="emphasis"><em>ls</em></span> but fails to match our regular expression which also expects the hostname `ls_known_host’:</p><pre class="screen">$ vi dbg.log
 ...
-expect: does "ssh -F fixtures/ssh/config ls\r\nls           lsattr       lsb_release  lshal        lshw         lsmod        lsof         lspci        lspcmcia     lspgpot      lss16toppm\r\nlsusb\r\n/@ssh -F fixtures/ssh/config ls" (spawn_id exp9) match regular expression "^ssh -F fixtures/ssh/config ls\r\n.*ls.*ls_known_host.*\r\n/@ssh -F fixtures/ssh/config ls$"? no</pre><p>Now let's fix ssh completion:</p><pre class="screen">$ vi ../contrib/ssh
+expect: does "ssh -F fixtures/ssh/config ls\r\nls           lsattr       lsb_release  lshal        lshw         lsmod        lsof         lspci        lspcmcia     lspgpot      lss16toppm\r\nlsusb\r\n/@ssh -F fixtures/ssh/config ls" (spawn_id exp9) match regular expression "^ssh -F fixtures/ssh/config ls\r\n.*ls.*ls_known_host.*\r\n/@ssh -F fixtures/ssh/config ls$"? no</pre><p>Now let’s fix ssh completion:</p><pre class="screen">$ vi ../contrib/ssh
 ...</pre><p>until the test shows:</p><pre class="screen">$ ./runCompletion ssh.exp
 ...
                 === completion Summary ===
 
-# of expected passes            2</pre></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_fixing_a_unit_test"></a>5.3. Fixing a unit test</h2></div></div></div><p>Now let's consider a unit test failure.  First you're triggered by unsuccessful tests:</p><pre class="screen">$ ./runUnit
+# of expected passes            2</pre></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_fixing_a_unit_test"></a>6.3. Fixing a unit test</h2></div></div></div><p>Now let’s consider a unit test failure.  First you’re triggered by unsuccessful tests:</p><pre class="screen">$ ./runUnit
 ...
                 === unit Summary ===
 
 # of expected passes            1
 # of unexpected failures        1</pre><p>Take a look in <code class="literal">log/unit.log</code> to find out which specific command is failing.</p><pre class="screen">$ vi log/unit.log</pre><p>Search for <code class="literal">UNRESOLVED</code> or <code class="literal">FAIL</code>.  From there scroll up to see which <code class="literal">.exp</code> test is failing:</p><pre class="screen">/@Running ./unit/_known_hosts_real.exp ...
 ...
-FAIL: Environment should stay clean</pre><p>In this case it appears <code class="literal">_known_hosts_real.exp</code> is causing the problem.  Isolate the <code class="literal">_known_hosts_real</code> test by specifying just <code class="literal">_known_hosts_real.exp</code> to run.  Furthermore add the <code class="literal">—debug</code> flag, so output gets logged in <code class="literal">dbg.log</code>:</p><pre class="screen">$ ./runUnit _known_hosts_real.exp --debug
+FAIL: Environment should stay clean</pre><p>In this case it appears <code class="literal">_known_hosts_real.exp</code> is causing the problem.  Isolate the <code class="literal">_known_hosts_real</code> test by specifying just <code class="literal">_known_hosts_real.exp</code> to run.  Furthermore add the <code class="literal">--debug</code> flag, so output gets logged in <code class="literal">dbg.log</code>:</p><pre class="screen">$ ./runUnit _known_hosts_real.exp --debug
 ...
                 === completion Summary ===
 
 # of expected passes            1
-# of unexpected failures        1</pre><p>Now, if we haven't already figured out the problem, we can have a detailed look in <code class="literal">dbg.log</code> to find out what's going wrong.  Open <code class="literal">dbg.log</code> and search for <code class="literal">UNRESOLVED</code> (or <code class="literal">FAIL</code> if that's what you're looking for):</p><pre class="screen">FAIL: Environment should stay clean</pre><p>From there, search up for the first line saying:</p><pre class="screen">expect: does "..." match regular expression "..."</pre><p>This tells you where the actual output differs from the expected output.  In this case it looks like the the function <code class="literal">_known_hosts_real</code> is unexpectedly modifying global variables <code class="literal">cur</code> and <code class="literal">flag</code>.  In case you need to modify the test:</p><pre class="screen">$ vi lib/unit/_known_hosts_real.exp</pre></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_rationale"></a>Chapter 6. Rationale</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#_naming_conventions">6.1. Naming conventions</a></span></dt><dd><dl><dt><span class="section"><a href="#_test_suite_or_testsuite">6.1.1. Test suite or testsuite</a></span></dt><dt><span class="section"><a href="#_script_generate">6.1.2. script/generate</a></span></dt></dl></dd></dl></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_naming_conventions"></a>6.1. Naming conventions</h2></div></div></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="_test_suite_or_testsuite"></a>6.1.1. Test suite or testsuite</h3></div></div></div><p>The primary Wikipedia page is called
-<a class="ulink" href="http://en.wikipedia.org/wiki/Test_suite" target="_top">test suite</a> and not testsuite, so that's what this
-document sticks to.</p></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="_script_generate"></a>6.1.2. script/generate</h3></div></div></div><p>The name and location of this code generation script come from Ruby on Rails' <a class="ulink" href="http://en.wikibooks.org/wiki/Ruby_on_Rails/Tools/Generators" target="_top">script/generate</a>.</p></div></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_reference"></a>Chapter 7. Reference</h2></div></div></div><p>Within test scripts the following library functions can be used:</p></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="Test_context"></a>Chapter 8. Test context</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#_what_happens_when_tests_are_run">8.1. What happens when tests are run?</a></span></dt><dd><dl><dt><span class="section"><a href="#_completion">8.1.1. completion</a></span></dt><dt><span class="section"><a href="#_install">8.1.2. install</a></span></dt><dt><span class="section"><a href="#_unit">8.1.3. unit</a></span></dt></dl></dd><dt><span class="section"><a href="#_bashrc">8.2. bashrc</a></span></dt><dt><span class="section"><a href="#_inputrc">8.3. inputrc</a></span></dt></dl></div><p>The test environment needs to be put to fixed states when testing.  For instance the bash prompt (PS1) is set to the current test directory, followed by an ampersand (@).  The default settings for <code class="literal">bash</code> reside in <code class="literal">config/bashrc</code> and <code class="literal">config/inputrc</code>.</p><p>For each tool (completion, install, unit) a slightly different context is in effect.</p><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_what_happens_when_tests_are_run"></a>8.1. What happens when tests are run?</h2></div></div></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="_completion"></a>8.1.1. completion</h3></div></div></div><p>When the completions are tested, invoking DejaGnu will result in a call to <code class="literal">completion_start()</code> which in turn will start <code class="literal">bash —rcfile config/bashrc</code>.</p><div class="example"><a id="id2682547"></a><p class="title"><b>Example 8.1. What happens when completion tests are run?</b></p><div class="example-contents"><pre class="screen">               | runtest --tool completion
+# of unexpected failures        1</pre><p>Now, if we haven’t already figured out the problem, we can have a detailed look in <code class="literal">dbg.log</code> to find out what’s going wrong.  Open <code class="literal">dbg.log</code> and search for <code class="literal">UNRESOLVED</code> (or <code class="literal">FAIL</code> if that’s what you’re looking for):</p><pre class="screen">FAIL: Environment should stay clean</pre><p>From there, search up for the first line saying:</p><pre class="screen">expect: does "..." match regular expression "..."</pre><p>This tells you where the actual output differs from the expected output.  In this case it looks like the the function <code class="literal">_known_hosts_real</code> is unexpectedly modifying global variables <code class="literal">cur</code> and <code class="literal">flag</code>.  In case you need to modify the test:</p><pre class="screen">$ vi lib/unit/_known_hosts_real.exp</pre></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_rationale"></a>Chapter 7. Rationale</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#_naming_conventions">7.1. Naming conventions</a></span></dt><dd><dl><dt><span class="section"><a href="#_test_suite_or_testsuite">7.1.1. Test suite or testsuite</a></span></dt><dt><span class="section"><a href="#_script_generate">7.1.2. script/generate</a></span></dt></dl></dd></dl></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_naming_conventions"></a>7.1. Naming conventions</h2></div></div></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="_test_suite_or_testsuite"></a>7.1.1. Test suite or testsuite</h3></div></div></div><p>The primary Wikipedia page is called
+<a class="ulink" href="http://en.wikipedia.org/wiki/Test_suite" target="_top">test suite</a> and not testsuite, so that’s what this
+document sticks to.</p></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="_script_generate"></a>7.1.2. script/generate</h3></div></div></div><p>The name and location of this code generation script come from Ruby on Rails' <a class="ulink" href="http://en.wikibooks.org/wiki/Ruby_on_Rails/Tools/Generators" target="_top">script/generate</a>.</p></div></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="_reference"></a>Chapter 8. Reference</h2></div></div></div><p>Within test scripts the following library functions can be used:</p></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="Test_context"></a>Chapter 9. Test context</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#_what_happens_when_tests_are_run">9.1. What happens when tests are run?</a></span></dt><dd><dl><dt><span class="section"><a href="#_completion">9.1.1. completion</a></span></dt><dt><span class="section"><a href="#_install">9.1.2. install</a></span></dt><dt><span class="section"><a href="#_unit">9.1.3. unit</a></span></dt></dl></dd><dt><span class="section"><a href="#_bashrc">9.2. bashrc</a></span></dt><dt><span class="section"><a href="#_inputrc">9.3. inputrc</a></span></dt></dl></div><p>The test environment needs to be put to fixed states when testing.  For instance the bash prompt (PS1) is set to the current test directory, followed by an ampersand (@).  The default settings for <code class="literal">bash</code> reside in <code class="literal">config/bashrc</code> and <code class="literal">config/inputrc</code>.</p><p>For each tool (completion, install, unit) a slightly different context is in effect.</p><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_what_happens_when_tests_are_run"></a>9.1. What happens when tests are run?</h2></div></div></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="_completion"></a>9.1.1. completion</h3></div></div></div><p>When the completions are tested, invoking DejaGnu will result in a call to <code class="literal">completion_start()</code> which in turn will start <code class="literal">bash --rcfile config/bashrc</code>.</p><div class="example"><a id="id2644163"></a><p class="title"><b>Example 9.1. What happens when completion tests are run?</b></p><div class="example-contents"><pre class="screen">               | runtest --tool completion
                V
     +----------+-----------+
     |  lib/completion.exp  |
@@ -87,7 +117,7 @@ document sticks to.</p></div><div class="section" lang="en" xml:lang="en"><div c
     +----------+-----------+
     |   completion_exit()  |
     | (lib/completion.exp) |
-    +----------------------+</pre></div></div><br class="example-break" /><p>Setting up bash once within <code class="literal">completion_start()</code> has the speed advantage that bash - and bash-completion - need only initialize once when testing multiple completions, e.g.:</p><pre class="screen">    runtest --tool completion alias.exp cd.exp</pre></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="_install"></a>8.1.2. install</h3></div></div></div><div class="example"><a id="id2682611"></a><p class="title"><b>Example 8.2. What happens when install tests are run?</b></p><div class="example-contents"><pre class="screen">                 | runtest --tool install
+    +----------------------+</pre></div></div><br class="example-break" /><p>Setting up bash once within <code class="literal">completion_start()</code> has the speed advantage that bash - and bash-completion - need only initialize once when testing multiple completions, e.g.:</p><pre class="screen">    runtest --tool completion alias.exp cd.exp</pre></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="_install"></a>9.1.2. install</h3></div></div></div><div class="example"><a id="id2646974"></a><p class="title"><b>Example 9.2. What happens when install tests are run?</b></p><div class="example-contents"><pre class="screen">                 | runtest --tool install
                  V
             +----+----+
             | DejaGnu |
@@ -101,7 +131,7 @@ document sticks to.</p></div><div class="section" lang="en" xml:lang="en"><div c
                  V
     +------------+------------+
     | (file: lib/install.exp) |
-    +-------------------------+</pre></div></div><br class="example-break" /></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="_unit"></a>8.1.3. unit</h3></div></div></div><div class="example"><a id="id2682641"></a><p class="title"><b>Example 8.3. What happens when unit tests are run?</b></p><div class="example-contents"><pre class="screen">               | runtest --tool unit
+    +-------------------------+</pre></div></div><br class="example-break" /></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="_unit"></a>9.1.3. unit</h3></div></div></div><div class="example"><a id="id2636096"></a><p class="title"><b>Example 9.3. What happens when unit tests are run?</b></p><div class="example-contents"><pre class="screen">               | runtest --tool unit
                V
           +----+----+
           | DejaGnu |
@@ -111,8 +141,7 @@ document sticks to.</p></div><div class="section" lang="en" xml:lang="en"><div c
     +----------+-----------+
     |          -           |
     | (file: lib/unit.exp) |
-    +----------------------+</pre></div></div><br class="example-break" /></div></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_bashrc"></a>8.2. bashrc</h2></div></div></div><p>This is the bash configuration file (bashrc) used for testing:</p><pre class="programlisting">
-# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
+    +----------------------+</pre></div></div><br class="example-break" /></div></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_bashrc"></a>9.2. bashrc</h2></div></div></div><p>This is the bash configuration file (bashrc) used for testing:</p><pre class="programlisting"># -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
 # ex: ts=8 sw=8 noet filetype=sh
 #
 # bashrc file for DejaGnu testsuite
@@ -134,9 +163,15 @@ export INPUTRC=$TESTDIR/config/inputrc
         # Ensure enough columns so expect doesn't have to care about line breaks
 stty columns 150
 
-. lib/library.sh
-</pre></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_inputrc"></a>8.3. inputrc</h2></div></div></div><p>This is the readline configuration file (inputrc) used for testing:</p><pre class="programlisting">
-# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
+        # Make sure default settings are in effect
+unset -v \
+    COMP_CONFIGURE_HINTS \
+    COMP_CVS_REMOTE \
+    COMP_KNOWN_HOSTS_WITH_HOSTFILE \
+    COMP_TAR_INTERNAL_PATHS
+
+        # Load bash testsuite helper functions
+. lib/library.sh</pre></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_inputrc"></a>9.3. inputrc</h2></div></div></div><p>This is the readline configuration file (inputrc) used for testing:</p><pre class="programlisting"># -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
 # ex: ts=8 sw=8 noet filetype=sh
 #
 # Readline init file for DejaGnu testsuite
@@ -151,5 +186,4 @@ set completion-query-items -1
         # Display completions sorted horizontally, not vertically
 set print-completions-horizontally on
         # Don't use pager when showing completions
-set page-completions off
-</pre></div></div></div><div class="index"><div class="titlepage"><div><div><h2 class="title"><a id="_index"></a>Index</h2></div></div></div><div class="index"></div></div></div></body></html>
+set page-completions off</pre></div></div></div><div class="index"><div class="titlepage"><div><div><h2 class="title"><a id="_index"></a>Index</h2></div></div></div><div class="index"></div></div></div></body></html>
diff --git a/doc/main.txt b/doc/main.txt
index d9cdd82..d8a3076 100644
--- a/doc/main.txt
+++ b/doc/main.txt
@@ -12,7 +12,7 @@ common Linux/UNIX commands, reducing the amount of typing sysadmins
 and programmers need to do on a daily basis.
 
 // include::intro.txt[]
-// include::bash_completion.txt[]
+include::bash_completion.txt[]
 
 include::styleguide.txt[]
 include::testing.txt[]
diff --git a/doc/makeHtml.sh b/doc/makeHtml.sh
index 8e52eff..ed29ab4 100755
--- a/doc/makeHtml.sh
+++ b/doc/makeHtml.sh
@@ -1,4 +1,4 @@
 #!/bin/bash -eu
 
 [ -d html~ ] || mkdir html~
-a2x -D html~ -d book -f xhtml main.txt
+a2x -D html~ -d book -f xhtml --unsafe main.txt
diff --git a/doc/testing.txt b/doc/testing.txt
index fe41597..8ebb29d 100644
--- a/doc/testing.txt
+++ b/doc/testing.txt
@@ -72,7 +72,7 @@ Maintenance
 Adding a completion test
 ~~~~~~~~~~~~~~~~~~~~~~~~
 
-You can add script/generate to add a test.
+You can run `cd test && ./generate` to add a test.
 
 
 Fixing a completion test
diff --git a/test/config/bashrc b/test/config/bashrc
index 7a50f6e..8539977 100644
--- a/test/config/bashrc
+++ b/test/config/bashrc
@@ -20,4 +20,12 @@ export INPUTRC=$TESTDIR/config/inputrc
 	# Ensure enough columns so expect doesn't have to care about line breaks
 stty columns 150
 
+	# Make sure default settings are in effect
+unset -v \
+    COMP_CONFIGURE_HINTS \
+    COMP_CVS_REMOTE \
+    COMP_KNOWN_HOSTS_WITH_HOSTFILE \
+    COMP_TAR_INTERNAL_PATHS
+
+	# Load bash testsuite helper functions
 . lib/library.sh
diff --git a/test/unit/_known_hosts_real.exp b/test/unit/_known_hosts_real.exp
index a698b92..71966d5 100644
--- a/test/unit/_known_hosts_real.exp
+++ b/test/unit/_known_hosts_real.exp
@@ -32,6 +32,32 @@ expect {
 sync_after_int
 
 
+set test "Hosts should have username prefix and colon suffix"
+set hosts [get_hosts]
+    # Hosts `gee', `hus' and `jar' are defined in ./fixtures/_known_hosts_real/config
+    # Hosts `doo' and `ike' are defined in ./fixtures/_known_hosts_real/known_hosts
+lappend hosts doo gee hus ike jar
+set hosts [lsort -ascii $hosts]
+set expected {}
+foreach host $hosts {
+    lappend expected "user@$host:"
+}; # foreach
+set expected [join $expected "\\s+"]
+    # Call _known_hosts
+set cmd {_known_hosts_real -acF fixtures/_known_hosts_real/config 'user@'; echo_array COMPREPLY}
+send "$cmd\r"
+expect -ex "$cmd\r\n"
+expect {
+    -re "^$expected\r\n/@$"  { pass "$test" }
+    -re /@ { unresolved "$test at prompt" }
+    default { unresolved "$test" }
+}; # expect
+
+
+sync_after_int
+
+
+
 set test "Config file containing space should work"
 set hosts [get_hosts]
     # Hosts `gee' and `hus' are defined in ./fixtures/_known_hosts_real/spaced  conf
@@ -54,4 +80,29 @@ expect {
 sync_after_int
 
 
+set test "Empty COMP_KNOWN_HOSTS_WITH_HOSTFILE should omit HOSTFILE"
+assert_bash_exec "COMP_KNOWN_HOSTS_WITH_HOSTFILE="
+set hosts {}
+    # Hosts `gee', `hus' and `jar' are defined in ./fixtures/_known_hosts_real/config
+    # Hosts `doo' and `ike' are defined in ./fixtures/_known_hosts_real/known_hosts
+lappend hosts doo gee hus ike jar
+set hosts [lsort -ascii $hosts]
+set hosts [join $hosts "\\s+"]
+    # Call _known_hosts
+set cmd {_known_hosts_real -aF fixtures/_known_hosts_real/config ''; echo_array COMPREPLY}
+send "$cmd\r"
+expect -ex "$cmd\r\n"
+expect {
+    -re "^$hosts\r\n/@$"  { pass "$test" }
+    -re /@ { unresolved "$test at prompt" }
+    default { unresolved "$test" }
+}; # expect
+sync_after_int
+assert_bash_exec "unset -v COMP_KNOWN_HOSTS_WITH_HOSTFILE"
+
+
+
+sync_after_int
+
+
 teardown

-- 
bash-completion



More information about the Bash-completion-commits mailing list