tests: add highlight extension tests
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Sat, 22 Mar 2008 20:16:30 +0100
changeset 6355 3b841c189ab7
parent 6354 57a47660b319
child 6356 b34b876d1f6f
tests: add highlight extension tests
tests/hghave
tests/test-highlight
tests/test-highlight.out
--- a/tests/hghave	Sat Mar 22 18:33:10 2008 +0100
+++ b/tests/hghave	Sat Mar 22 20:16:30 2008 +0100
@@ -107,6 +107,13 @@
     finally:
         os.rmdir(d)
 
+def has_pygments():
+    try:
+        import pygments
+        return True
+    except ImportError:
+        return False
+
 checks = {
     "baz": (has_baz, "GNU Arch baz client"),
     "cvs": (has_cvs, "cvs client"),
@@ -123,6 +130,7 @@
     "symlink": (has_symlink, "symbolic links"),
     "tla": (has_tla, "GNU Arch tla client"),
     "unix-permissions": (has_unix_permissions, "unix-style permissions"),
+    "pygments": (has_pygments, "Pygments source highlighting library"),
 }
 
 def list_features():
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-highlight	Sat Mar 22 20:16:30 2008 +0100
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+"$TESTDIR/hghave" pygments || exit 80
+
+cat <<EOF >> $HGRCPATH
+[extensions]
+hgext.highlight =
+EOF
+
+hg init test
+cd test
+cp $TESTDIR/get-with-headers.py ./
+hg ci -Ama
+
+echo % hg serve
+hg serve -p $HGPORT -d -n test --pid-file=hg.pid -A access.log -E errors.log
+cat hg.pid >> $DAEMON_PIDS
+
+echo % hgweb filerevision
+("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/get-with-headers.py') \
+    | sed "s/[0-9]* years ago/long ago/g"
+
+echo % hgweb fileannotate
+("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/get-with-headers.py') \
+    | sed "s/[0-9]* years ago/long ago/g"
+
+echo % errors encountered
+cat errors.log
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-highlight.out	Sat Mar 22 20:16:30 2008 +0100
@@ -0,0 +1,129 @@
+adding get-with-headers.py
+% hg serve
+% hgweb filerevision
+200 Script output follows
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<link rel="icon" href="/static/hgicon.png" type="image/png">
+<meta name="robots" content="index, nofollow" />
+<link rel="stylesheet" href="/static/style.css" type="text/css" />
+
+<link rel="stylesheet" href="/static/highlight.css" type="text/css" />
+<title>test:get-with-headers.py</title>
+</head>
+<body>
+
+<div class="buttons">
+<a href="/log/0">changelog</a>
+<a href="/shortlog/0">shortlog</a>
+<a href="/tags">tags</a>
+<a href="/rev/79ee608ca36d">changeset</a>
+<a href="/file/79ee608ca36d/">files</a>
+<a href="/log/79ee608ca36d/get-with-headers.py">revisions</a>
+<a href="/annotate/79ee608ca36d/get-with-headers.py">annotate</a>
+<a href="/raw-file/79ee608ca36d/get-with-headers.py">raw</a>
+</div>
+
+<h2>get-with-headers.py</h2>
+
+<table>
+<tr>
+ <td class="metatag">changeset 0:</td>
+ <td><a href="/rev/79ee608ca36d">79ee608ca36d</a></td></tr>
+
+
+<tr>
+ <td class="metatag">author:</td>
+ <td>&#116;&#101;&#115;&#116;</td></tr>
+<tr>
+ <td class="metatag">date:</td>
+ <td>Thu Jan 01 00:00:00 1970 +0000 (long ago)</td></tr>
+<tr>
+ <td class="metatag">permissions:</td>
+ <td>-rwxr-xr-x</td></tr>
+<tr>
+  <td class="metatag">description:</td>
+  <td>a</td>
+</tr>
+</table>
+
+<pre>
+<div class="parity0"><a class="lineno" href="#l1" id="l1">     1</a><span class="c">#!/usr/bin/env python</span></div><div class="parity1"><a class="lineno" href="#l2" id="l2">     2</a></div><div class="parity0"><a class="lineno" href="#l3" id="l3">     3</a><span class="n">__doc__</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;This does HTTP get requests given a host:port and path and returns</span></div><div class="parity1"><a class="lineno" href="#l4" id="l4">     4</a><span class="s">a subset of the headers plus the body of the result.&quot;&quot;&quot;</span></div><div class="parity0"><a class="lineno" href="#l5" id="l5">     5</a></div><div class="parity1"><a class="lineno" href="#l6" id="l6">     6</a><span class="k">import</span> <span class="nn">httplib</span><span class="o">,</span> <span class="nn">sys</span></div><div class="parity0"><a class="lineno" href="#l7" id="l7">     7</a><span class="n">headers</span> <span class="o">=</span> <span class="p">[</span><span class="n">h</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="k">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">3</span><span class="p">:]]</span></div><div class="parity1"><a class="lineno" href="#l8" id="l8">     8</a><span class="n">conn</span> <span class="o">=</span> <span class="n">httplib</span><span class="o">.</span><span class="n">HTTPConnection</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">1</span><span class="p">])</span></div><div class="parity0"><a class="lineno" href="#l9" id="l9">     9</a><span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">&quot;GET&quot;</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">2</span><span class="p">])</span></div><div class="parity1"><a class="lineno" href="#l10" id="l10">    10</a><span class="n">response</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">getresponse</span><span class="p">()</span></div><div class="parity0"><a class="lineno" href="#l11" id="l11">    11</a><span class="k">print</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">reason</span></div><div class="parity1"><a class="lineno" href="#l12" id="l12">    12</a><span class="k">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">headers</span><span class="p">:</span></div><div class="parity0"><a class="lineno" href="#l13" id="l13">    13</a>    <span class="k">if</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span></div><div class="parity1"><a class="lineno" href="#l14" id="l14">    14</a>        <span class="k">print</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">))</span></div><div class="parity0"><a class="lineno" href="#l15" id="l15">    15</a><span class="k">print</span></div><div class="parity1"><a class="lineno" href="#l16" id="l16">    16</a><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">read</span><span class="p">())</span></div><div class="parity0"><a class="lineno" href="#l17" id="l17">    17</a></div><div class="parity1"><a class="lineno" href="#l18" id="l18">    18</a><span class="k">if</span> <span class="mf">200</span> <span class="o">&lt;=</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="o">&lt;=</span> <span class="mf">299</span><span class="p">:</span></div><div class="parity0"><a class="lineno" href="#l19" id="l19">    19</a>    <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mf">0</span><span class="p">)</span></div><div class="parity1"><a class="lineno" href="#l20" id="l20">    20</a><span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span></div>
+</pre>
+
+
+<div class="logo">
+<a href="http://www.selenic.com/mercurial/">
+<img src="/static/hglogo.png" width=75 height=90 border=0 alt="mercurial"></a>
+</div>
+
+</body>
+</html>
+
+% hgweb fileannotate
+200 Script output follows
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<link rel="icon" href="/static/hgicon.png" type="image/png">
+<meta name="robots" content="index, nofollow" />
+<link rel="stylesheet" href="/static/style.css" type="text/css" />
+
+<link rel="stylesheet" href="/static/highlight.css" type="text/css" />
+<title>test: get-with-headers.py annotate</title>
+</head>
+<body>
+
+<div class="buttons">
+<a href="/log/0">changelog</a>
+<a href="/shortlog/0">shortlog</a>
+<a href="/tags">tags</a>
+<a href="/rev/79ee608ca36d">changeset</a>
+<a href="/file/79ee608ca36d/">files</a>
+<a href="/file/79ee608ca36d/get-with-headers.py">file</a>
+<a href="/log/79ee608ca36d/get-with-headers.py">revisions</a>
+<a href="/raw-annotate/79ee608ca36d/get-with-headers.py">raw</a>
+</div>
+
+<h2>Annotate get-with-headers.py</h2>
+
+<table>
+<tr>
+ <td class="metatag">changeset 0:</td>
+ <td><a href="/rev/79ee608ca36d">79ee608ca36d</a></td></tr>
+
+
+<tr>
+ <td class="metatag">author:</td>
+ <td>&#116;&#101;&#115;&#116;</td></tr>
+<tr>
+ <td class="metatag">date:</td>
+ <td>Thu Jan 01 00:00:00 1970 +0000 (long ago)</td></tr>
+<tr>
+ <td class="metatag">permissions:</td>
+ <td>-rwxr-xr-x</td></tr>
+<tr>
+  <td class="metatag">description:</td>
+  <td>a</td>
+</tr>
+</table>
+
+<br/>
+
+<table cellspacing="0" cellpadding="0">
+<tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l1">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l1" id="l1">     1</a></td><td><pre><span class="c">#!/usr/bin/env python</span></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l2">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l2" id="l2">     2</a></td><td><pre></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l3">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l3" id="l3">     3</a></td><td><pre><span class="n">__doc__</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;This does HTTP get requests given a host:port and path and returns</span></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l4">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l4" id="l4">     4</a></td><td><pre><span class="s">a subset of the headers plus the body of the result.&quot;&quot;&quot;</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l5">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l5" id="l5">     5</a></td><td><pre></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l6">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l6" id="l6">     6</a></td><td><pre><span class="k">import</span> <span class="nn">httplib</span><span class="o">,</span> <span class="nn">sys</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l7">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l7" id="l7">     7</a></td><td><pre><span class="n">headers</span> <span class="o">=</span> <span class="p">[</span><span class="n">h</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="k">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">3</span><span class="p">:]]</span></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l8">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l8" id="l8">     8</a></td><td><pre><span class="n">conn</span> <span class="o">=</span> <span class="n">httplib</span><span class="o">.</span><span class="n">HTTPConnection</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">1</span><span class="p">])</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l9">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l9" id="l9">     9</a></td><td><pre><span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">&quot;GET&quot;</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">2</span><span class="p">])</span></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l10">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l10" id="l10">    10</a></td><td><pre><span class="n">response</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">getresponse</span><span class="p">()</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l11">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l11" id="l11">    11</a></td><td><pre><span class="k">print</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">reason</span></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l12">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l12" id="l12">    12</a></td><td><pre><span class="k">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">headers</span><span class="p">:</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l13">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l13" id="l13">    13</a></td><td><pre>    <span class="k">if</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l14">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l14" id="l14">    14</a></td><td><pre>        <span class="k">print</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">))</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l15">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l15" id="l15">    15</a></td><td><pre><span class="k">print</span></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l16">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l16" id="l16">    16</a></td><td><pre><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">read</span><span class="p">())</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l17">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l17" id="l17">    17</a></td><td><pre></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l18">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l18" id="l18">    18</a></td><td><pre><span class="k">if</span> <span class="mf">200</span> <span class="o">&lt;=</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="o">&lt;=</span> <span class="mf">299</span><span class="p">:</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l19">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l19" id="l19">    19</a></td><td><pre>    <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mf">0</span><span class="p">)</span></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l20">&#116;&#101;&#115;&#116;@0</a></td><td><a class="lineno" href="#l20" id="l20">    20</a></td><td><pre><span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span></pre></td></tr>
+</table>
+
+
+<div class="logo">
+<a href="http://www.selenic.com/mercurial/">
+<img src="/static/hglogo.png" width=75 height=90 border=0 alt="mercurial"></a>
+</div>
+
+</body>
+</html>
+
+% errors encountered