Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

(RT #79891) Added tests to see if indentation is preserved.

  • Loading branch information...
commit 8b000e61b25923181e76741f5bd7f97be57a45db 1 parent 5de3797
@guillaumeaubert guillaumeaubert authored
Showing with 85 additions and 0 deletions.
  1. +1 −0  MANIFEST
  2. +84 −0 t/12-parse_stack_trace-indentation.t
View
1  MANIFEST
@@ -14,6 +14,7 @@ lib/Carp/Parse/Redact.pm
t/00-load.t
t/10-parse_stack_trace.t
t/11-parse_stack_trace-regexp.t
+t/12-parse_stack_trace-indentation.t
t/CallerInformation-Redacted/00-load.t
t/CallerInformation-Redacted/10-new.t
t/CallerInformation-Redacted/20-get_line.t
View
84 t/12-parse_stack_trace-indentation.t
@@ -0,0 +1,84 @@
+#!perl -T
+
+use strict;
+use warnings;
+
+use Carp::Parse::Redact;
+use Data::Dump;
+use Test::Exception;
+use Test::More tests => 2;
+
+
+# The test stack trace, along with the indentation of callers.
+my $stack_trace = q|Test at test/lib/Spock/test.t line 116
+ main::test_trace('gift_message', 'Happy Birthday from Timmy', 'password', 'thereisnotry', 'planet', 'degobah', 'ship_zip', 01138, 'username', 'yoda') called at test/lib/Spock/test.t line 61
+ main::__ANON__() called at /home/spock/site_perl/5.14.2/Try/Tiny.pm line 76
+ eval {...} called at /home/spock/site_perl/5.14.2/Try/Tiny.pm line 67
+ Try::Tiny::try('CODE(0xb3d4f48)', 'Try::Tiny::Finally=REF(0xaf503f0)') called at test/lib/Spock/test.t line 69
+|;
+
+# The expected redacted lines.
+# Note: tabs are for formatting of this array only, they are removed before
+# comparing expected vs output.
+my $expected_redacted_lines =
+[
+ q|Test at test/lib/Spock/test.t line 116|,
+ q| main::test_trace(
+ "gift_message",
+ "Happy Birthday from Timmy",
+ "password",
+ "[redacted]",
+ "planet",
+ "degobah",
+ "ship_zip",
+ "[redacted]",
+ "username",
+ "[redacted]",
+ ) called at test/lib/Spock/test.t line 61|,
+ q| main::__ANON__() called at /home/spock/site_perl/5.14.2/Try/Tiny.pm line 76|,
+ q| Try::Tiny::try("CODE(0xb3d4f48)", "Try::Tiny::Finally=REF(0xaf503f0)") called at test/lib/Spock/test.t line 69|,
+];
+
+my $parsed_stack_trace;
+lives_ok(
+ sub
+ {
+ $parsed_stack_trace = Carp::Parse::Redact::parse_stack_trace(
+ $stack_trace,
+ sensitive_argument_names =>
+ [
+ 'password',
+ 'username',
+ 'ship_zip',
+ ],
+ );
+ },
+ 'Parse test stack trace.',
+);
+
+subtest(
+ 'Sensitive information is redacted out.',
+ sub
+ {
+ plan( tests => scalar( @$expected_redacted_lines ) );
+
+ for ( my $i = 0; $i < scalar( @$expected_redacted_lines ); $i++ )
+ {
+ # Get the redacted line.
+ my $redacted_line = $parsed_stack_trace->[$i]->get_redacted_line();
+ chomp( $redacted_line );
+
+ # Get the expected result, and remove any tabs,
+ # which are used for formatting in the test array.
+ my $expected = $expected_redacted_lines->[$i];
+ $expected =~ s/\t+//g;
+
+ is(
+ $redacted_line,
+ $expected,
+ "(caller $i) The line is redacted and indented correctly.",
+ );
+ }
+ },
+);
+
Please sign in to comment.
Something went wrong with that request. Please try again.