Roxen.git / server / modules / configuration / roxen_test.pike

version» Context lines:

Roxen.git/server/modules/configuration/roxen_test.pike:45:    return 0;    return 1;   }      int tests, ltests, test_num;   int lskipped;   int fails, lfails;   int pass;   string tag_test_data;   int bkgr_fails; + bool testsuite_pass_1_ok;      void background_failure()   {    // Called in all configurations/instances of this module, by    // describe_backtrace() (roxenloader.pike), in self test mode. We    // need to check whether it's for us or not by checking if we're    // running currently.    if (is_running()) {    // Log something to make these easier to locate in the noisy test logs.    report_error ("################ Background failure\n");
Roxen.git/server/modules/configuration/roxen_test.pike:198:    return;   }      void xml_use_module(Parser.HTML file_parser, mapping m, string c,    mapping ignored, multiset(string) used_modules) {    conf->enable_module(c);    used_modules[c] = 1;    return;   }    - void xml_test(Parser.HTML file_parser, mapping args, string c, -  mapping(int:RXML.PCode) p_code_cache) { -  -  if (roxen.is_shutting_down()) return; -  -  test_num++; -  RXML.PCode p_code = p_code_cache[test_num]; -  if (pass == 2 && !p_code) return; // Not a test that produced p-code. -  -  ltests++; -  tests++; -  -  string rxml=""; -  mixed res; -  -  string indent( int l, string what ) + private 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 test_error( string message, mixed ... args ) + private void test_error( string rxml, int line, string message, mixed ... args )   {    if( sizeof( args ) )    message = sprintf( message, @args );    message = (pass == 2 ? "[Pass 2 (p-code)] " : "[Pass 1 (source)] ") + message;    if( verbose )    if( strlen( rxml ) )    report_debug("FAIL\n" );    report_error (indent (2, sprintf ("################ Error at line %d:", -  file_parser->at_line()))); +  line)));    if( strlen( rxml ) )    report_debug( indent(2, rxml ) );    rxml="";    report_error( indent(2, message ) ); -  + } +  + // Returns true if all modules are available, else false. + // Calls test_error for every module not found. + private bool assert_modules(string modules, Parser.HTML file_parser) + { +  bool modules_found = true; +  foreach (modules / ",", string module) { +  module = String.trim_whites(module); +  if (conf->find_module(module)) { +  continue; +  } else { +  modules_found = false; +  test_error("", file_parser->at_line(), +  "Required module %O not available.\n", module); +  } +  } +  return modules_found; + } +  + void xml_test(Parser.HTML file_parser, mapping args, string c, +  mapping(int:RXML.PCode) p_code_cache) { +  +  if (roxen.is_shutting_down()) return; +  +  test_num++; +  RXML.PCode p_code = p_code_cache[test_num]; +  if (pass == 2 && !p_code) return; // Not a test that produced p-code. +  +  ltests++; +  tests++; +  +  if (args->modules && !assert_modules(args->modules, file_parser)) { +  fails++; +  lfails++; +  return; +  } +  +  string rxml=""; +  mixed res; +  +  void test_error( string message, mixed ... args ) +  { +  global::test_error(rxml, file_parser->at_line(), message, @args);    };    -  string test_ok( ) +  void test_ok( )    {    rxml = "";    if( verbose )    report_debug( "PASS\n" );    };    -  string test_test( string test ) +  void test_test( string test )    {    if( verbose && strlen( rxml ) )    test_ok();    rxml = test;    if( verbose )    {    report_debug( "%4d %-69s (pass %d) ",    ltests, sprintf("%O", test)[..68], pass);    }    };
Roxen.git/server/modules/configuration/roxen_test.pike:538:    master()->describe_backtrace (error));    fails++;    lfails++;    }       if( verbose && strlen( rxml ) ) test_ok();    return;   }      mixed xml_testsuite(Parser.HTML file_parser, mapping args, string c, -  mapping(int:RXML.PCode) p_code_cache) { +  mapping(int:RXML.PCode) p_code_cache) + {    if (roxen.is_shutting_down()) {    return ({}); // Stop parsing.    } -  string env = args["if-not-env"]; -  if (env && getenv(env)) { -  if (pass == 1) { -  report_debug("Skipping tests since env. var %s is defined.\n", env); +  if (pass == 2 && !testsuite_pass_1_ok) { +  // If pass 1 failed we should not try again. Stop parsing. +  return ({}); +  } +  string forbidden_env = args["if-not-env"]; +  if (forbidden_env && getenv(forbidden_env)) { +  testsuite_pass_1_ok = false; +  report_debug("Skipping tests since env. var %s is defined.\n", +  forbidden_env);    // Count number of tests we are skipping.    Roxen.get_xml_parser()->add_quote_tag ("!--", "", "--")    ->add_tags ((["test": lambda () { lskipped++; }]))    ->finish (c); -  +  return ({}); // Stop parsing.    } -  +  if (args->modules && !assert_modules(args->modules, file_parser)) { +  testsuite_pass_1_ok = false; +  // Count all tests as failed. +  Roxen.get_xml_parser()->add_quote_tag ("!--", "", "--") +  ->add_tags ((["test": lambda () { +  ltests++; +  tests++; +  fails++; +  lfails++; +  }])) +  ->finish (c);    return ({}); // Stop parsing.    } -  +  testsuite_pass_1_ok = true;    return c; // Continue to parse content withing this tag.   }      class TagTestData {    inherit RXML.Tag;    constant name = "test-data";    constant flags = RXML.FLAG_DONT_CACHE_RESULT;    array(RXML.Type) result_types = ({RXML.t_html (RXML.PXml)});       class Frame {
Roxen.git/server/modules/configuration/roxen_test.pike:590:    // El cheapo xml header parser.    if (has_prefix (data, "<?xml")) {    sscanf (data, "%[^\n]", string s);    if (sscanf (s, "%*sencoding=\"%s\"", s) == 2)    data = Charset.decoder (s)->feed (data)->drain();    }       ltests=0;    lfails=0;    lskipped=0; +  testsuite_pass_1_ok=true; // true must be default since the testsuite tag is +  // optional.       test_num = 0;    pass = 1;    Roxen.get_xml_parser()->add_containers( ([    "add-module" : xml_add_module,    "drop-module" : xml_dummy /* xml_drop_module */,    "use-module": xml_use_module,    "testsuite" : xml_testsuite,    "test" : xml_test,    "comment": xml_comment,
Roxen.git/server/modules/configuration/roxen_test.pike:617:       Roxen.get_xml_parser()->add_quote_tag ("!--", "", "--")    ->add_tags ((["test": lambda () {test_tags++;}]))    ->finish (data);       if(test_tags != (ltests + lskipped))    report_warning("Possibly XML error in testsuite - "    "got %d test tags but did %d tests.\n",    test_tags, ltests);    +  if (testsuite_pass_1_ok) {    // Go through them again, evaluation from the p-code this time.    test_num = 0;    pass = 2;    Roxen.get_xml_parser()->add_containers( ([    "add-module" : xml_dummy /* xml_add_module */,    "drop-module" : xml_drop_module,    "testsuite" : xml_testsuite,    "test" : xml_test,    "comment": xml_comment,    ]) )->    set_extra (p_code_cache, used_modules)->    finish(data); -  +  }       if (roxen.is_shutting_down()) return;       foreach (indices (used_modules), string modname)    conf->disable_module (modname);    -  report_debug("Did %d tests, failed on %d, skipped %d%s.\n", -  ltests, lfails, lskipped, +  string fail_str = lfails ? ("failed on " + lfails) : "zero failures"; +  report_debug("Did %d tests, %s, skipped %d%s.\n", +  ltests, fail_str, lskipped,    bkgr_fails ?    ", detected " + bkgr_fails + " background failures" : "");       if (bkgr_fails) {    fails += bkgr_fails;    bkgr_fails = 0;    }       continue_run_tests();   }
Roxen.git/server/modules/configuration/roxen_test.pike:658:      // --- Pike test files -----------------------      void run_pike_tests(object test, string path)   {    void update_num_tests(int tsts, int fail)    {    tests+=tsts;    fails+=fail;    -  report_debug("Did %d tests, failed on %d%s.\n", tsts, fail, +  string fail_str = fail ? ("failed on " + fail) : "zero failures"; +  report_debug("Did %d tests, %s%s.\n", tsts, fail_str,    bkgr_fails ?    ", detected " + bkgr_fails + " background failures" : "");       if (bkgr_fails) {    fails += bkgr_fails;    bkgr_fails = 0;    }       continue_run_tests();    };
Roxen.git/server/modules/configuration/roxen_test.pike:737:    return;    }    }    }       running = 0;    finished = 1;    if(is_last_test_configuration())    {    // Note that e.g. the distmaker parses this string. -  report_debug("\nDid a grand total of %d tests, %d failed.\n\n", -  tests, fails); +  string fail_str = fails ? ("failed on " + fails) : "zero failures"; +  report_debug("\nDid a grand total of %d tests, %s.\n\n", +  tests, fail_str);    roxen.restart(0, fails > 127 ? 127 : fails);    }    else    foreach(roxen.configurations, Configuration config)    if(config->call_provider("roxen_test", "do_continue", tests, fails))    return;   }      void do_tests()   {