[BACK]Return to network_tests.t CVS log [TXT][DIR] Up to [local] / HOPE / Net-OpenAMD / t

Diff for /HOPE/Net-OpenAMD/t/network_tests.t between version 1.3 and 1.9

version 1.3, 2010/06/26 17:50:40 version 1.9, 2010/07/13 03:27:06
Line 1 
Line 1 
 #!perl  #!perl
 package NetworkTests;  package NetworkTests;
   
 # $AFresh1: network_tests.t,v 1.2 2010/06/26 16:47:01 andrew Exp $  # $AFresh1: network_tests.t,v 1.8 2010/07/13 00:14:43 andrew Exp $
   
 use strict;  use strict;
 use warnings;  use warnings;
   
 use Test::More;  use Test::More;
   use Test::Deep;
 use Net::OpenAMD;  use Net::OpenAMD;
   use Data::Dumper;
   
 if ( !caller() ) {  if ( !caller() ) {
     if ( $ENV{'NETWORK_TESTS'} ) {      if ( $ENV{'NETWORK_TESTS'} ) {
           plan tests => 13;
         # plan tests => ??;  
     }      }
     else {      else {
         plan skip_all => "Set env NETWORK_TESTS to test";          plan skip_all =>
               'Network test.  Set $ENV{NETWORK_TESTS} to a true value to run.';
     }      }
   
     my $amd = Net::OpenAMD->new();      my $amd
           = Net::OpenAMD->new( { base_uri => 'http://api.hope.net/api/', } );
     run_tests($amd);      run_tests($amd);
   
     done_testing();      #done_testing();
 }  }
   
 1;  1;
Line 29 
Line 32 
 sub run_tests {  sub run_tests {
     my ($amd) = @_;      my ($amd) = @_;
   
       my @interests = (
           "new tech",           "activism",
           "radio",              "lockpicking",
           "crypto",             "privacy",
           "ethics",             "telephones",
           "social engineering", "hacker spaces",
           "hardware hacking",   "nostalgia",
           "communities",        "science",
           "government",         "network security",
           "malicious software", "pen testing",
           "web",                "niche hacks",
           "media"
       );
       my %cmp = (
           single_line   => re('^[^\n]+$'),
           multi_line    => re('^.*$'),
           digits        => re('^\d+$'),
           track         => any( 'Lovelace', 'Tesla', 'Bell', 'Hooper' ),
           area          => any('Engressia'),
           interests     => any(@interests),
           all_interests => bag(@interests),
           coordinate    => re('^\d\d\.\d+$'),
           boolean => any( 'True', 'False' ),
       );
   
       #$cmp{speaker} = $cmp{single_line};
   
     my %tests = (      my %tests = (
         location => [          location => [
             {   args   => undef,              {   args   => undef,
                 expect => {},                  expect => array_each(
                       {   area   => $cmp{area},
                           user   => $cmp{digits},
                           button => $cmp{boolean},
                           x      => $cmp{coordinate},
                           y      => $cmp{coordinate},
                           time   => $cmp{single_line},
                       }
                   ),
             },              },
               { args => { user => 'user0' },
                       expect => array_each(),
               },
         ],          ],
         speakers => [          speakers => [
             {   args   => undef,              {   args   => undef,
                 expect => {},                  expect => array_each(
                       {   name => $cmp{single_line},
                           bio  => $cmp{multi_line},
                       }
                   ),
             },              },
         ],          ],
         talks => [          talks => [
             {   args   => undef,              {   args   => undef,
                 expect => {},                  expect => array_each(
                       {   abstract  => $cmp{single_line},
                           interests => array_each( $cmp{interests} ),
                           speakers  => array_each( $cmp{single_line} ),
                           time      => $cmp{single_line},
                           title     => $cmp{multi_line},
                           track     => $cmp{track},
                       }
                   ),
             },              },
         ],          ],
         interests => [          interests => [
             {   args   => undef,              {   args   => undef,
                 expect => {},                  expect => $cmp{all_interests},
             },              },
         ],          ],
         users => [          users => [
             {   args   => undef,              {   args   => undef,
                 expect => {},                  expect => array_each(
                       {   interests => array_each( $cmp{interests} ),
                           name      => $cmp{single_line},
                           x         => $cmp{coordinate},
                           y         => $cmp{coordinate},
                       }
                   ),
             },              },
         ],          ],
         stats => [          stats => [
             {   args   => undef,              {   args   => undef,
                 expect => {},                  expect => qr/^Unused \s feature/xms,
             },              },
         ],          ],
     );      );
Line 67 
Line 126 
             no warnings 'uninitialized';              no warnings 'uninitialized';
             my $result;              my $result;
             eval { $result = $amd->$method( $test->{args} ) };              eval { $result = $amd->$method( $test->{args} ) };
             is( $@,      undef,           "AMD->$method($test->{args})" );              if ( ref $test->{expect} eq 'Regexp' ) {
             is( $result, $test->{expect}, 'got expected result' );                  like( $@, $test->{expect}, "AMD->$method($test->{args})" );
               }
               elsif ( ref $test->{expect} ) {
                   is( $@, '', "AMD->$method($test->{args})" );
                   cmp_deeply( $result, $test->{expect},
                             "AMD->$method($test->{args}) - "
                           . 'got expected result' );
               }
               else {
                   is( $@, $test->{expect}, "AMD->$method($test->{args})" );
               }
         }          }
     }      }
 }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.9

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>