-
Notifications
You must be signed in to change notification settings - Fork 14
/
parse_results.php
175 lines (156 loc) · 5.23 KB
/
parse_results.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
require_once 'vendor/autoload.php';
use Symfony\Component\Yaml\Yaml;
/**
* Drupal.org project url pattern.
*/
const DRUPAL_PROJECT_URL = 'https://www.drupal.org/project';
$config = Yaml::parse(file_get_contents(__DIR__ . '/config.yml'));
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader);
// First, move simpletest results into the correct project.
if (is_dir('www/simpletest')) {
foreach (new DirectoryIterator('www/simpletest') as $simpletest_file_info) {
if ($simpletest_file_info->isFile() && preg_match('/Drupal_(.+)_Tests/', $simpletest_file_info->getFilename(), $matches)) {
$name = $matches[1];
// Find the right project.
do {
// Check if a project with that name exists.
if (is_dir('www/' . $name . '/simpletest')) {
// Move the file, continue with the next.
rename($simpletest_file_info->getPathname(), 'www/' . $name . '/simpletest/' . $simpletest_file_info->getFilename());
continue 2;
}
// If the name has no _ left, continue with the next file, display an
// error.
if (strpos($name, '_') === FALSE) {
print "ERROR: Failed to move simpletest to the correct project: " . $simpletest_file_info->getFilename() . "\n";
}
} while ($name = substr($name, 0, strrpos($name, '_')));
}
}
rmdir('www/simpletest');
}
$projects = parse_results('www');
$total_counter = (count($projects));
$failed_counter = 0;
$changed_counter = 0;
if (is_dir('www-old')) {
$projects_old = parse_results('www-old');
}
foreach ($projects as $name => &$project) {
$has_changed = FALSE;
if (!isset($projects_old[$name])) {
$project['new'] = TRUE;
continue;
}
$project['url'] = get_project_url($name, $config['projects']);
foreach (['phpunit', 'simpletest'] as $framework) {
if (!isset($project[$framework])) {
continue;
}
foreach ($project[$framework] as $type => $count) {
if (isset($projects_old[$name][$framework][$type])) {
$project[$framework][$type . '_diff'] = $count - $projects_old[$name][$framework][$type];
if ($project[$framework][$type . '_diff'] != 0) {
$project[$framework]['different'] = 'different';
$has_changed = TRUE;
}
}
}
}
if ($project['is_failed'] == TRUE) {
$failed_counter++;
}
if ($has_changed) {
$changed_counter++;
}
}
ksort($projects);
$index = $twig->render('index.html.twig',
['projects' => $projects, 'timestamp' => date('Y-m-d H:i:s T'),
'total_counter' => $total_counter,
'failed_counter' => $failed_counter,
'passed_counter' => $total_counter - $failed_counter,
'changed_counter' => $changed_counter,
]
);
file_put_contents('www/index.html', $index);
file_put_contents('www/projects.json', json_encode($projects, JSON_PRETTY_PRINT));
/**
* @param $path
*
* @return array
*/
function parse_results($path) {
$projects = array();
foreach (new DirectoryIterator($path) as $file_info) {
if ($file_info->isDir() && !$file_info->isDot() && $file_info->getFilename() != 'assets') {
$project = [
'name' => $file_info->getFilename(),
'phpunit' => [],
'simpletest' => [],
'is_failed' => FALSE,
];
$phpunit_file = $file_info->getPathName() . '/phpunit.xml';
if (file_exists($phpunit_file) && filesize($phpunit_file) > 0) {
$phpunit = simplexml_load_file($phpunit_file);
$project['phpunit']['assertions'] = (int) $phpunit->testsuite['assertions'];
$project['phpunit']['failures'] = (int) $phpunit->testsuite['failures'];
$project['phpunit']['errors'] = (int) $phpunit->testsuite['errrors'];
if ($project['phpunit']['failures'] > 0 || $project['phpunit']['errors'] > 0) {
$project['is_failed'] = TRUE;
}
}
$project['simpletest'] = get_simpletest_results($file_info->getPathname());
if ($project['simpletest']['failures'] > 0 || $project['simpletest']['errors'] > 0) {
$project['is_failed'] = TRUE;
}
$projects[$project['name']] = $project;
}
}
return $projects;
}
/**
* Returns simpletest test results.
*
* @param $simpletest_dir
*
* @return array
*/
function get_simpletest_results($project_dir) {
$results = [
'assertions' => 0,
'failures' => 0,
'errors' => 0,
];
$simpletest_dir = $project_dir . '/simpletest';
if (is_dir($simpletest_dir)) {
foreach (new DirectoryIterator($simpletest_dir) as $simpletest_file_info) {
if ($simpletest_file_info->isFile()) {
$simpletest_xml = simplexml_load_file($simpletest_file_info->getRealPath());
$results['assertions'] += count($simpletest_xml->testcase);
$results['failures'] += count($simpletest_xml->xpath('/testsuite/testcase/failure'));
$results['errors'] += count($simpletest_xml->xpath('/testsuite/testcase/error'));
}
}
}
return $results;
}
/**
* Get a project url.
*
* @param string $name
* Project name
* @param array $config
* An array keyed by project name that can contain an override url.
*
* @return string
* Project url.
*/
function get_project_url($name, $config) {
if (isset($config[$name]['url'])) {
return $config[$name]['url'];
}
return DRUPAL_PROJECT_URL . '/' . $name;
}