Skip to content

Commit

Permalink
pygmentize.pl: warn if an error occured
Browse files Browse the repository at this point in the history
There's now a test that checks the error message when no pygmentize tool
can be found on the PATH.
  • Loading branch information
kensanata committed Jul 16, 2015
1 parent f993903 commit eb0738d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion modules/pygmentize.pl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ sub DoPygmentize {


RequestLockDir('pygmentize') or return ''; RequestLockDir('pygmentize') or return '';
WriteStringToFile("$TempDir/pygmentize", $contents); WriteStringToFile("$TempDir/pygmentize", $contents);
my $output = `pygmentize $lexer -f html -O encoding=utf8 $args -- \Q$TempDir/pygmentize\E`; my $output = `pygmentize $lexer -f html -O encoding=utf8 $args -- \Q$TempDir/pygmentize\E 2>&1`;
ReleaseLockDir('pygmentize'); ReleaseLockDir('pygmentize');


utf8::decode($output); utf8::decode($output);

if ($?) {
$output = $q->p($q->strong($output)) # "sh: pygmentize: command not found"
. $q->pre($contents);
}
return $output; return $output;
} }
25 changes: 25 additions & 0 deletions t/pygmentize.t
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (C) 2015 Alex Schroeder <alex@gnu.org>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.

require 't/test.pl';
package OddMuse;
use Test::More tests => 2;

add_module('pygmentize.pl');

$ENV{PATH} = '.'; # pygmentize is not installed in the current directory
$page = apply_rules(newlines('{{{\ntest\n}}}\n'));
test_page($page,
'sh: pygmentize: command not found',
'<pre>test</pre>');

0 comments on commit eb0738d

Please sign in to comment.