Permalink
Browse files

pygmentize.pl: warn if an error occured

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 eb0738dedc9cf41bb5a1de7cb0f2230517d9b2a0
Showing with 31 additions and 1 deletion.
  1. +6 −1 modules/pygmentize.pl
  2. +25 −0 t/pygmentize.t
View
@@ -52,9 +52,14 @@ sub DoPygmentize {
RequestLockDir('pygmentize') or return '';
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');
utf8::decode($output);
if ($?) {
$output = $q->p($q->strong($output)) # "sh: pygmentize: command not found"
. $q->pre($contents);
}
return $output;
}
View
@@ -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.