|
| 1 | +<?php |
| 2 | + |
| 3 | +$file = file_get_contents("output.txt"); |
| 4 | +if(!$file){ |
| 5 | + echo "{\"json\": false}"; |
| 6 | + die(); |
| 7 | +} |
| 8 | + |
| 9 | +$output = [ |
| 10 | + "schema-version" => "0.0.1", |
| 11 | + "results" => [ |
| 12 | + "tool" => "", |
| 13 | + "summary" => [ |
| 14 | + "tests" => "", |
| 15 | + "passed" => "", |
| 16 | + "failed" => "", |
| 17 | + "start_time" => 0, |
| 18 | + "stop_time" => "", |
| 19 | + ], |
| 20 | + "tests" => [ |
| 21 | + [ |
| 22 | + "name" => "test1", |
| 23 | + "status" => "passed", |
| 24 | + "duration" => 1, |
| 25 | + "message" => "passed", |
| 26 | + "log" => "none", |
| 27 | + ], |
| 28 | + ], |
| 29 | + ], |
| 30 | +]; |
| 31 | + |
| 32 | +$runtime_loc = strpos($file,"Runtime:"); |
| 33 | +$configuration_loc = strpos($file, "Configuration:", $runtime_loc); |
| 34 | +$tool = trim(substr($file, $runtime_loc + 8, $configuration_loc - $runtime_loc - 8)); |
| 35 | + |
| 36 | +$output['results']['tool'] = $tool; |
| 37 | + |
| 38 | +$time_loc = strpos($file, "Time:"); |
| 39 | +$memory_loc = strpos($file, "Memory:", $time_loc); |
| 40 | +$time = trim(substr($file, $time_loc + 5, $memory_loc - $time_loc - 7)); |
| 41 | +$timeInSeconds = strtotime("1970-01-01T00:".$time, 0); // #TODO add support for hour+ long runs |
| 42 | + |
| 43 | +$output['results']['summary']['stop_time'] = $timeInSeconds; |
| 44 | + |
| 45 | +// Check for OK, which is all passed |
| 46 | +$ok_loc = strpos($file, "OK ("); |
| 47 | +if($ok_loc !== false) { |
| 48 | + $tests_loc = strpos($file, "tests,", $ok_loc); |
| 49 | + $total_tests = trim(substr($file, $ok_loc + 4, $tests_loc - $ok_loc - 4)); |
| 50 | + |
| 51 | + $output['results']['summary']['tests'] = (int)$total_tests; |
| 52 | + $output['results']['summary']['passed'] = (int)$total_tests; |
| 53 | + $output['results']['summary']['failed'] = 0; |
| 54 | +}else{ |
| 55 | + //look for failure state |
| 56 | + $tests_loc = strpos($file, "Tests: "); |
| 57 | + $end_tests_loc = strpos($file, ",", $tests_loc); |
| 58 | + $total_tests = substr($file, $tests_loc + 6, $end_tests_loc - $tests_loc - 6); |
| 59 | + |
| 60 | + $assertions_loc = strpos($file, "Assertions: ", $tests_loc); |
| 61 | + $end_assertions_loc = strpos($file, ",", $assertions_loc); |
| 62 | + $assertions = substr($file, $assertions_loc + 12, $end_assertions_loc - $assertions_loc - 12); |
| 63 | + |
| 64 | + $failures_loc = strpos($file, "Errors: ", $assertions_loc); |
| 65 | + $end_failures_loc = strpos($file, ".", $failures_loc); |
| 66 | + $failures = trim(substr($file, $failures_loc + 7, $end_failures_loc - $failures_loc - 7)); |
| 67 | + |
| 68 | + $output['results']['summary']['tests'] = (int)$assertions; |
| 69 | + $output['results']['summary']['passed'] = $assertions - $failures; |
| 70 | + $output['results']['summary']['failed'] = (int)$failures; |
| 71 | +} |
| 72 | +echo json_encode($output); |
0 commit comments