forked from qownnotes/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-tests.php
executable file
·80 lines (65 loc) · 2.12 KB
/
run-tests.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
#!/usr/bin/env php
<?php
$dirs = array_filter(glob('*'), 'is_dir');
$testHelper = new TestHelper();
foreach ($dirs as $dir) {
$testHelper->testDirectory($dir);
}
$errors = $testHelper->errors;
if (count($errors) > 0) {
foreach($errors as $dir => $scriptErrors) {
print "Directory '$dir'\n";
foreach($scriptErrors as $error) {
print " $error\n";
}
}
exit(1);
}
print "No errors were found\n";
exit(0);
class TestHelper {
public $errors = array();
/**
* Tests the files in a directory
*/
public function testDirectory($dir) {
$errors = array();
$jsonData = file_get_contents($dir . "/info.json");
$data = json_decode($jsonData, true);
if ($data["name"] == "") {
$errors[] = "No name was entered!";
}
$identifier = $data["identifier"];
if ($identifier == "") {
$errors[] = "No identifier was entered!";
} elseif (preg_match('/[^a-z0-9\-_]/', $identifier)) {
$errors[] = "Invalid charactes were found in identifier '$identifier'!";
}
if ($data["description"] == "") {
$errors[] = "No description was entered!";
}
$script = $data["script"];
if ($script == "") {
$errors[] = "No script was entered!";
} elseif (!file_exists($dir . "/" . $script)) {
$errors[] = "Script '$script' doesn't exist!";
}
if ($data["version"] == "") {
$errors[] = "No version was entered!";
}
if (isset($data["platforms"])) {
if (!is_array($data["platforms"])) {
$errors[] = "'platforms' has to be an array!";
} else {
foreach ($data["platforms"] as $platform) {
if (!in_array($platform, array("linux", "macos", "windows"))) {
$errors[] = "Unsupported platform '$platform', only 'linux', 'macos' and 'windows' are allowed!";
}
}
}
}
if (count($errors) > 0) {
$this->errors[$dir] = $errors;
}
}
}