From: Andrew Ruthven Date: Thu, 14 Jun 2012 10:45:04 +0000 (+1200) Subject: Add tests! X-Git-Tag: 0.10.1~2 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13a98613a522aea43498d96b0e0297fad1d54d34;p=mythtv-status.git Add tests! --- diff --git a/Makefile b/Makefile index 0fe889d..696ab04 100755 --- a/Makefile +++ b/Makefile @@ -18,6 +18,9 @@ DEBS=$(foreach release, $(releases), build/$(release)/$(deb)) RELEASE_FILES=$(orig_tarball) build/tarball/mythtv-status-${version}.tar.gz $(DEBS) +TEST_VERBOSE=0 +TEST_FILES=t/*.t + all: release release: $(RELEASE_FILES) @@ -53,6 +56,11 @@ publish: $(RELEASE_FILES) @chmod o+r $(tarball_dir)/*-$(version).* @ln -sf `basename $(tarball)` $(tarball_dir)/$(package)-latest.tar.gz + +test: + PERL_DL_NONLAZY=1 perl "-MExtUtils::Command::MM" "-e" "test_harness($(TEST_VERBOSE))" $(TEST_FILES) + + clean: @rm -rf build @rm -f ../$(package)*.changes ../$(package)*.dsc ../$(package)*.tar.gz ../$(package)*.deb diff --git a/t/01-test-help.t b/t/01-test-help.t new file mode 100644 index 0000000..ac9c3a5 --- /dev/null +++ b/t/01-test-help.t @@ -0,0 +1,109 @@ +#!usr/bin/perl + +use Test::More tests => 2; +use FindBin qw/$Bin/; + +# Test that the blurb of how to get help is printed. +my $out = `$Bin/../bin/mythtv-status --zzz 2>&1`; + +my $expected = <&1`; + +$expected = <[ --email
...] + Send the output to the listed email addresses. By default the + encoder status, currently recording shows and time till next + recording is surpressed from the email. + + To turn the additional blocks on you can use --encoders, + --recording-now and/or --next-recording. + + --email-only-on-alert + Only send an email out (if --email is present) if there is an alert + (i.e., schedule conflict or low disk space). + + -?, --help + Display help. + + --file + Load XML from the file specified instead of querying a MythTV + backend. Handy for debugging things. + + --guide-days-warn + Warn if the number of days of guide data present is equal to or + below this level. Default is 2 days. + + -h HOST, --host=HOST + The host to check, defaults to localhost. + + --nostatus, --noencoders, --norecording-now, --noscheduled-recordings, + --noschedule-conflicts, --nonext-recording, --nototal-disk-space, + --nodisk-space, --noguide-data, --noauto-expire + Suppress displaying blocks of the output if they would normally be + displayed. + + -p PORT, --port=PORT + The port to use when connecting to MythTV, defaults to 6544. + + --oneliner-bullets + Insert asterisks (*) before each of the oneliners to stop some email + clients from thinking the oneliner block is a paragraph and trying + to word wrap them. + + --auto-expire + Display the shows due to auto expire (output is normally + suppressed). + + --auto-expire-count + How many of the auto expire shows to display, defaults to 10. + + --recording-in-warn + If the "Next Recording In" time is less than this amount, display it + in red. This in seconds, and defaults to 3600 (1 hour). + + --verbose + Have slightly more verbose output. This includes any warnings that + might be generated while parsing the XML. + + -v, --version + Show the version of mythtv-status and then exit. + +EOF + +ok($out eq $expected, '--help generates help output'); diff --git a/t/05-v0.20-clean.t b/t/05-v0.20-clean.t new file mode 100644 index 0000000..1fe77f1 --- /dev/null +++ b/t/05-v0.20-clean.t @@ -0,0 +1,89 @@ +#!usr/bin/perl -w + +use strict; +use Test::More tests => 42; +use FindBin qw/$Bin/; + +my $xml = "$Bin/xml/single-filesytem-0.20.2.xml"; + +# Test that the blurb of how to get help is printed. +my $out = `$Bin/../bin/mythtv-status --file $xml 2>&1`; + +#diag($out); + +like($out, qr/MythTV status for localhost/, 'Header is present'); +like($out, qr/^Status..........: Thu Nov 29 2007, 6:43 PM$/m, 'Status line is present'); +like($out, qr/^Total Disk Space: Total space is 100\.0 GB, with 72\.2 GB used \(72.2%\)$/m, 'Total disk space is present'); +unlike($out, qr/^Guide Data\.*:/m, 'Guide data warning is not present'); +like($out, qr/^Encoders:\s+cerberus \(9\) - Recording$/m, 'Encoder is present, and recording'); +like($out, qr/^Recording Now:\s+3 News \(TV3\) Ends: 19:00:00$/m, 'Recording now is present (the news)'); + +# Test that the status isn't present if --nostatus is passed. + +$out = `$Bin/../bin/mythtv-status --file $xml --nostatus 2>&1`; + +like($out, qr/MythTV status for localhost/, 'Header is present'); +unlike($out, qr/^Status\.*:/m, 'Status line is not present'); +like($out, qr/^Total Disk Space: Total space is 100\.0 GB, with 72\.2 GB used \(72.2%\)$/m, 'Total disk space is present'); +unlike($out, qr/^Guide Data\.*:/m, 'Guide data warning is not present'); +like($out, qr/^Encoders:\s+cerberus \(9\) - Recording$/m, 'Encoder is present, and recording'); +like($out, qr/^Recording Now:\s+3 News \(TV3\) Ends: 19:00:00$/m, 'Recording now is present (the news)'); + +# Test that the disk space isn't present if --nototal-disk-space is passed. + +$out = `$Bin/../bin/mythtv-status --file $xml --nototal-disk-space 2>&1`; + +like($out, qr/MythTV status for localhost/, 'Header is present'); +like($out, qr/^Status\.*: Thu Nov 29 2007, 6:43 PM$/m, 'Status line is present'); +unlike($out, qr/^Total Disk Space: Total space is 100\.0 GB, with 72\.2 GB used \(72.2%\)$/m, 'Total disk space is not present'); +unlike($out, qr/^Guide Data\.*:/m, 'Guide data warning is not present'); +like($out, qr/^Encoders:\s+cerberus \(9\) - Recording$/m, 'Encoder is present, and recording'); +like($out, qr/^Recording Now:\s+3 News \(TV3\) Ends: 19:00:00$/m, 'Recording now is present (the news)'); + +# Test that the encoders details aren't present if --noencoders is passed. + +$out = `$Bin/../bin/mythtv-status --file $xml --noencoders 2>&1`; + +like($out, qr/MythTV status for localhost/, 'Header is present'); +like($out, qr/^Status\.*: Thu Nov 29 2007, 6:43 PM$/m, 'Status line is present'); +like($out, qr/^Total Disk Space: Total space is 100\.0 GB, with 72\.2 GB used \(72.2%\)$/m, 'Total disk space is present'); +unlike($out, qr/^Guide Data\.*:/m, 'Guide data warning is not present'); +unlike($out, qr/^Encoders:\s+cerberus \(9\) - Recording$/m, 'Encoder is not present'); +like($out, qr/^Recording Now:\s+3 News \(TV3\) Ends: 19:00:00$/m, 'Recording now is present (the news)'); + +# Test that the recording now details aren't present if --norecording-now is passed. + +$out = `$Bin/../bin/mythtv-status --file $xml --norecording-now 2>&1`; + +like($out, qr/MythTV status for localhost/, 'Header is present'); +like($out, qr/^Status\.*: Thu Nov 29 2007, 6:43 PM$/m, 'Status line is present'); +like($out, qr/^Total Disk Space: Total space is 100\.0 GB, with 72\.2 GB used \(72.2%\)$/m, 'Total disk space is present'); +unlike($out, qr/^Guide Data\.*:/m, 'Guide data warning is not present'); +like($out, qr/^Encoders:\s+cerberus \(9\) - Recording$/m, 'Encoder is present, and recording'); +unlike($out, qr/^Recording Now:\s+3 News \(TV3\) Ends: 19:00:00$/m, 'Recording now is not present'); + +# Test that the encoder details for a recording are present if --encoder-details is passed. + +$out = `$Bin/../bin/mythtv-status --file $xml --encoder-details 2>&1`; + +#diag($out); + +like($out, qr/MythTV status for localhost/, 'Header is present'); +like($out, qr/^Status..........: Thu Nov 29 2007, 6:43 PM$/m, 'Status line is present'); +like($out, qr/^Total Disk Space: Total space is 100\.0 GB, with 72\.2 GB used \(72.2%\)$/m, 'Total disk space is present'); +unlike($out, qr/^Guide Data\.*:/m, 'Guide data warning is not present'); +like($out, qr/^Encoders:\s+cerberus \(9\) - Recording$/m, 'Encoder is present, and recording'); +like($out, qr/^Recording Now:\s+3 News \(TV3, Enc: 9, Chan: 3\) Ends: 19:00:00$/m, 'Recording now is present (the news) with encoder details'); + +# Test that the encoder details for a recording are present if --encoder-details is passed. + +$out = `$Bin/../bin/mythtv-status --file $xml --oneliner-bullets 2>&1`; + +#diag($out); + +like($out, qr/MythTV status for localhost/, 'Header is present'); +like($out, qr/^\* Status..........: Thu Nov 29 2007, 6:43 PM$/m, 'Status line is present (with bullet)'); +like($out, qr/^\* Total Disk Space: Total space is 100\.0 GB, with 72\.2 GB used \(72.2%\)$/m, 'Total disk space is present (with bullet)'); +unlike($out, qr/^Guide Data\.*:/m, 'Guide data warning is not present'); +like($out, qr/^Encoders:\s+cerberus \(9\) - Recording$/m, 'Encoder is present, and recording'); +like($out, qr/^Recording Now:\s+3 News \(TV3\) Ends: 19:00:00$/m, 'Recording now is present (the news)'); diff --git a/t/10-v0.20-guide-data-warning.t b/t/10-v0.20-guide-data-warning.t new file mode 100644 index 0000000..f87e435 --- /dev/null +++ b/t/10-v0.20-guide-data-warning.t @@ -0,0 +1,31 @@ +#!usr/bin/perl -w + +use strict; +use Test::More tests => 6; +use FindBin qw/$Bin/; + +my $xml = "$Bin/xml/guide-data-1-day-0.20.xml"; + +# Test that the guide data warning is present. +my $out = `$Bin/../bin/mythtv-status --file $xml 2>&1`; + +#diag($out); + +like($out, qr/MythTV status for localhost/, 'Header is present'); +like($out, qr/^Guide Data\.*: There is 1 days worth of data, through to 2007-12-30/m, 'Guide data warning is present'); + +# If --noguide-data is passed in, then the guide data warning should be suppressed. +$out = `$Bin/../bin/mythtv-status --file $xml --noguide-data 2>&1`; + +#diag($out); + +like($out, qr/MythTV status for localhost/, 'Header is present'); +unlike($out, qr/^Guide Data\.*:/m, 'Guide data warning is not present (turned off)'); + +# If --guide-days-warn is set to something different, like 0, then the guide data warning should be suppressed. +$out = `$Bin/../bin/mythtv-status --file $xml --guide-days-warn 0 2>&1`; + +#diag($out); + +like($out, qr/MythTV status for localhost/, 'Header is present'); +unlike($out, qr/^Guide Data\.*:/m, 'Guide data warning is not present (warning level changed)'); diff --git a/testing/xml/guide-data-1-day.xml b/t/xml/guide-data-1-day-0.20.xml similarity index 100% rename from testing/xml/guide-data-1-day.xml rename to t/xml/guide-data-1-day-0.20.xml diff --git a/testing/xml/single-filesytem-0.20.2.xml b/t/xml/single-filesytem-0.20.2.xml similarity index 100% rename from testing/xml/single-filesytem-0.20.2.xml rename to t/xml/single-filesytem-0.20.2.xml