diff options
author | 2012-12-07 15:57:37 -0800 | |
---|---|---|
committer | 2012-12-07 15:57:37 -0800 | |
commit | 6a4f5fbca4137e4aa7bbcaff0bb0c6d07ef7a8a9 (patch) | |
tree | 8aaa14d62d22144b6b49bfab715c259ed1a944d6 | |
parent | 677af8b1b923532724857f6899ad7280ec6b7a21 (diff) |
refectored stats reporting
-rw-r--r-- | headless/src/main/java/com/galois/fiveui/HeadlessRunner.java | 96 |
1 files changed, 4 insertions, 92 deletions
diff --git a/headless/src/main/java/com/galois/fiveui/HeadlessRunner.java b/headless/src/main/java/com/galois/fiveui/HeadlessRunner.java index 7a61cd4..e6d8e45 100644 --- a/headless/src/main/java/com/galois/fiveui/HeadlessRunner.java +++ b/headless/src/main/java/com/galois/fiveui/HeadlessRunner.java @@ -58,7 +58,6 @@ import org.apache.log4j.BasicConfigurator; public class HeadlessRunner { private static Logger logger = Logger.getLogger("com.galois.fiveui.HeadlessRunner"); - private static Map<String, int[]> passFailMap = new HashMap<String, int[]>(); /** * @param args list of headless run description filenames @@ -157,7 +156,7 @@ public class HeadlessRunner { } } - // Process input files + // Major work: process input files ImmutableList<Result> results = null; for (String in: cmd.getArgs()) { HeadlessRunDescription descr = HeadlessRunDescription.parse(in); @@ -165,18 +164,15 @@ public class HeadlessRunner { BatchRunner runner = new BatchRunner(); results = runner.runHeadless(descr); logger.debug("runHeadless returned " + results.size() + " results"); - updateStats(results); // write results to the output stream as we go for (Result result : results) { outStream.println(result.toString()); } outStream.flush(); } - - reportStats(); outStream.close(); - // Write report files + // Write report files if requested if (cmd.hasOption("r") && results != null) { Reporter kermit = new Reporter(results); summaryFile.write(kermit.getSummary()); @@ -185,91 +181,7 @@ public class HeadlessRunner { byURLFile.close(); byRuleFile.write(kermit.getByRule()); byRuleFile.close(); - } - - } - - /** - * Update the global frequency map we're using to keep track of unique URLs, - * passes, and fails. - * - * TODO refector, absorb into Reporter class - */ - private static void updateStats(List<Result> results) throws ParseException { - // compute statistics on results - String url; - int pass, fail; - int[] passFailList; - Pattern numberPassedPattern = Pattern.compile("passed ([0-9]+) tests"); - Matcher matcher; - - for (Result result : results) { - pass = fail = 0; - url = result.getURL(); - if (result.getType() == ResType.Pass) { - // now we have to parse out how many tests passed - matcher = numberPassedPattern.matcher(result.getDesc()); - if (matcher.find()) { - try { - pass = Integer.parseInt(matcher.group(1)); - } catch (Exception e) { - e.printStackTrace(); - logger.error("error parsing pass rate from \"" + result.getDesc() + "\""); - } - } - } else if (result.getType() == ResType.Error) { - // each error result corresponds to one test - fail = 1; - } - - if (passFailMap.containsKey(url)) { - passFailList = passFailMap.get(url); - } else { - passFailList = new int[] { 0, 0}; - passFailMap.put(url, passFailList); - } - passFailList[0] += pass; - passFailList[1] += fail; - //passFailMap.put(url, passFailList); - } - } - - /** - * Report statistics on the headless run to the log. Note, "pass" - * means the URL passed all tests in the ruleset, but "fail" can be - * reported for the same test on multiple offenders in the page. - * - * TODO refactor this, absorb into Reporter class - */ - private static void reportStats() { - // report statistics on results - int uniqueURLs = passFailMap.size(); - String stats = "\n\nRESULT STATISTICS\n\n"; // update as we go - int pass, fail; - int[] passFailList; - - stats += "Unique URLs: " + uniqueURLs + "\n"; - for (String key: passFailMap.keySet()) { - passFailList = passFailMap.get(key); - pass = passFailList[0]; - fail = passFailList[1]; - stats += String.format("URL: %s, pass: %3d, fail %3d\n", - (key.length()>40 ? key.substring(0,37)+"..." : key + sp(40-key.length())), - pass, fail, pass+fail); - } - for (String s: stats.split("\n")) - logger.info(s); - } - - /** - * return a string of n spaces - */ - private static String sp(int n) { - String s = ""; - for (int i=0; i<n; i++) - s += " "; - return s; - } - + } + } } |