Introduce KORAPXMLTEI_DEBUG and document environment variables
Change-Id: I2d6232e475ea059ac1afee92a7fb088a39f61e7e
diff --git a/Readme.pod b/Readme.pod
index a71f3c8..d3cca5b 100644
--- a/Readme.pod
+++ b/Readme.pod
@@ -122,6 +122,22 @@
=back
+=head1 ENVIRONMENT VARIABLES
+
+=over 2
+
+=item B<KORAPXMLTEI_DEBUG>
+
+Activate minimal debugging.
+Defaults to C<false>.
+
+=item B<KORAPXMLTEI_INLINE>
+
+Process inline annotations, if present.
+Defaults to C<false>.
+
+=back
+
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2020, L<IDS Mannheim|https://www.ids-mannheim.de/>
diff --git a/lib/Test/KorAP/XML/TEI.pm b/lib/Test/KorAP/XML/TEI.pm
index 1581136..2208103 100644
--- a/lib/Test/KorAP/XML/TEI.pm
+++ b/lib/Test/KorAP/XML/TEI.pm
@@ -170,6 +170,18 @@
};
+# Check for stderr non-similarity
+sub stderr_unlike {
+ my ($self, $value, $desc) = @_;
+ return $self->_test(
+ 'unlike',
+ $self->{stderr},
+ $value,
+ _desc($desc, 'not similar to stderr')
+ );
+};
+
+
# Check if a zip exists
sub file_exists {
my ($self, $file, $desc) = @_;
diff --git a/script/tei2korapxml b/script/tei2korapxml
index ed6b488..09f2a81 100755
--- a/script/tei2korapxml
+++ b/script/tei2korapxml
@@ -38,6 +38,8 @@
our $VERSION_MSG = "\ntei2korapxml - v$VERSION\n";
+# Set to 1 for minimal more debug output (no need to be parametrized)
+use constant DEBUG => $ENV{KORAPXMLTEI_DEBUG} // 0;
# Parse options from the command line
GetOptions(
@@ -66,6 +68,8 @@
Log::Any::Adapter->set('Stderr', log_level => $log_level);
+$log->notice('Debugging is activated') if DEBUG;
+
#
# ~~~ parameter (mandatory) ~~~
#
@@ -108,7 +112,6 @@
my $_tok_dir = "base"; # name of directory for storing tokenization files
-my $_DEBUG = 0; # set to 1 for minimal more debug output (no need to be parametrized)
my $_XCT_LN = 0; # only for debugging: include line numbers in elements of $tree_data
# (see also manpage of XML::CompactTree::XS)
@@ -286,7 +289,7 @@
# ~ recursion ~
retr_info(1, \$tree_data->[2] ); # parse input data
- if ($_DEBUG) {
+ if (DEBUG) {
$log->debug("Writing (utf8-formatted) xml file $dir/$_data_file");
};
@@ -423,7 +426,7 @@
# Write header to zip
my $file = $header->dir . '/' . $_header_file;
- $log->debug("Writing file $file") if $_DEBUG;
+ $log->debug("Writing file $file") if DEBUG;
$header->to_zip($zipper->new_stream($file));
@@ -868,6 +871,22 @@
=back
+=head1 ENVIRONMENT VARIABLES
+
+=over 2
+
+=item B<KORAPXMLTEI_DEBUG>
+
+Activate minimal debugging.
+Defaults to C<false>.
+
+=item B<KORAPXMLTEI_INLINE>
+
+Process inline annotations, if present.
+Defaults to C<false>.
+
+=back
+
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2020, L<IDS Mannheim|https://www.ids-mannheim.de/>
diff --git a/t/script.t b/t/script.t
index e9d9dc9..88b3d2d 100644
--- a/t/script.t
+++ b/t/script.t
@@ -34,13 +34,25 @@
# Load example file
my $file = catfile($f, 'data', 'goe_sample.i5.xml');
+subtest 'Debugging' => sub {
+
+ my $t = test_tei2korapxml(
+ tmp => 'script_out',
+ file => $file,
+ param => '-ti',
+ env => 'KORAPXMLTEI_DEBUG=1'
+ )->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!)
+ ->stderr_like(qr!Debugging is activated!);
+};
+
subtest 'Basic processing' => sub {
my $t = test_tei2korapxml(
tmp => 'script_out',
file => $file,
param => '-ti'
- )->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!);
+ )->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!)
+ ->stderr_unlike(qr!Debugging is activated!);
# Uncompress GOE/header.xml from zip file