summaryrefslogtreecommitdiff
path: root/t/13-log.t
blob: f055f800701b7cb66541486ff4cdbb0ba9413675 (plain)
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. $ENV{TMPDIR} = 't/var';
  5. use Test::More tests => 13;
  6. use Test::Trap qw(trap $trap);
  7. use Data::Dumper;
  8. use LedgerSMB::Sysconfig;
  9. use LedgerSMB::Log;
  10. my @r;
  11. $LedgerSMB::Sysconfig::logging = 0;
  12. @r = trap{LedgerSMB::Log->print('test', 'message')};
  13. #is(LedgerSMB::Log->print('test', 'message'), 0);
  14. ok(!$trap->stderr,
  15. 'print: Unsetting LedgerSMB::Sysconfig::logging disables printing');
  16. $LedgerSMB::Sysconfig::logging = 1;
  17. @r = trap{LedgerSMB::Log->print('test', 'message')};
  18. ok($trap->stderr,
  19. 'print: Setting LedgerSMB::Sysconfig::logging enables printing');
  20. like($trap->stderr, qr/^\[.*?\] \[test\] $$ message/,
  21. 'print: Outputs correct message');
  22. @r = trap{LedgerSMB::Log->emerg('test')};
  23. like($trap->stderr, qr/^\[.*?\] \[emerg\] $$ test/,
  24. 'emerg: Outputs correct grouping');
  25. @r = trap{LedgerSMB::Log->alert('test')};
  26. like($trap->stderr, qr/^\[.*?\] \[alert\] $$ test/,
  27. 'alert: Outputs correct grouping');
  28. @r = trap{LedgerSMB::Log->crit('test')};
  29. like($trap->stderr, qr/^\[.*?\] \[crit\] $$ test/,
  30. 'crit: Outputs correct grouping');
  31. @r = trap{LedgerSMB::Log->error('test')};
  32. like($trap->stderr, qr/^\[.*?\] \[error\] $$ test/,
  33. 'error: Outputs correct grouping');
  34. @r = trap{LedgerSMB::Log->warn('test')};
  35. like($trap->stderr, qr/^\[.*?\] \[warn\] $$ test/,
  36. 'warn: Outputs correct grouping');
  37. @r = trap{LedgerSMB::Log->notice('test')};
  38. like($trap->stderr, qr/^\[.*?\] \[notice\] $$ test/,
  39. 'notice: Outputs correct grouping');
  40. @r = trap{LedgerSMB::Log->info('test')};
  41. like($trap->stderr, qr/^\[.*?\] \[info\] $$ test/,
  42. 'info: Outputs correct grouping');
  43. @r = trap{LedgerSMB::Log->debug('test')};
  44. like($trap->stderr, qr/^\[.*?\] \[debug\] $$ test/,
  45. 'debug: Outputs correct grouping');
  46. @r = trap{LedgerSMB::Log->dump('test')};
  47. like($trap->stderr, qr/^\[.*?\] \[debug\] $$ \$VAR1 = 'test'/,
  48. 'dump: Simple dump correct');
  49. @r = trap{LedgerSMB::Log->longmess('test')};
  50. like($trap->stderr, qr/^\[.*?\] \[debug\] $$ test at /,
  51. 'longmess: Outputs correct data');