Branch: Tag:

2001-01-31

2001-01-31 07:33:24 by Per Hedbor <ph@opera.com>

more tests, and simplified test API

Rev: server/etc/test/tests/RoxenTest_argcache.pike:1.1
Rev: server/etc/test/tests/RoxenTest_base.pike:1.3
Rev: server/etc/test/tests/pike_test_common.pike:1.6

1:   int current_test, tests_failed; - int verbose = 1; + int verbose;    -  + void create( int vb ) + { +  verbose = vb; + } +  +    string describe_arglist( array args )   {    array res = ({});
21:      void report_1st(function cb, array args, function check )   { +  if( !verbose ) +  return;    int checkid = ' ';    if( check == check_error )    checkid = '#';
29:    else if( check != check_is_configuration &&    check == check_is_module )    checkid = '~'; -  +     report_error("%3d %c%-66s ", current_test,    checkid,sprintf("%O("+describe_arglist( args )+")",cb)[..65]    );   }    -  + string indent( int l, string what ) + { +  array q = what/"\n"; + // if( q[-1] == "" ) q = q[..sizeof(q)-2]; +  string i = (" "*l+"| "); +  return i+q*("\n"+i)+"\n"; + } +    string do_describe_error( mixed err )   {    if( stringp( err ) ) -  return err + (strlen(err)?(err[-1] == '\n' ? "": "\n" ):""); +  return indent(2,err + (strlen(err)?(err[-1] == '\n' ? "": "\n" ):""));    err = (array)err;    err[1] = err[1][sizeof(err[1])-3..]; -  return describe_backtrace( err ); +  return indent(2, describe_backtrace( err ) );   }      void report_test_failure( mixed err, function cb, array args, int st )   { -  report_error(" FAILED\n"); -  if( err ) report_error( do_describe_error( err ) ); +  if( verbose ) +  report_debug(" FAILED\n"); +  report_debug(do_describe_error(sprintf( "%O( %s ) FAILED\n", +  cb, describe_arglist( args )))); +  if( err ) +  report_debug( do_describe_error( err ) );    tests_failed++;   }         void report_test_ok( mixed err, function cb, array args, int st )   { -  +  if( verbose ) +  {    int tt = (gethrtime()-st);    if( tt > 200000 )    report_debug(" %4dms\n", tt/1000);
61:    report_debug( " PASS\n" );   // if( err ) report_error( do_describe_error( err ) );   } + }       - mixed do_test( function check_return, function cb, mixed ... args ) + mixed test_generic( function check_return, function cb, mixed ... args )   {    current_test++;    mixed result;
121:    report_test_failure( err, cb, args, st );    else    if( !res ) -  report_test_failure( "expected non-zero", cb, args, st); +  report_test_failure( "expected non-zero, got 0", cb, args, st);    else    report_test_ok( err, cb, args, st );   }
190:    report_test_ok( err, cb, args, st );    };   } +  +  + mixed test( function f, mixed ... args ) + { +  return test_generic( 0, f, @args ); + } +  + mixed test_true( function f, mixed ... args ) + { +  return test_generic( check_true, f, @args ); + } +  + mixed test_false( function f, mixed ... args ) + { +  return test_generic( check_false, f, @args ); + } +  + mixed test_error( function f, mixed ... args ) + { +  return test_generic( check_error, f, @args ); + } +  + mixed test_equal( mixed what, function f, mixed ... args ) + { +  return test_generic( check_equal( what ), f, @args ); + } +  + mixed test_not_equal( mixed what, function f, mixed ... args ) + { +  return test_generic( check_not_equal( what ), f, @args ); + } +