1
0
Fork 0
mirror of https://github.com/marty-oehme/scripts.git synced 2024-12-22 07:58:08 +00:00
qownnotes-scripts/run-tests.php

81 lines
2.1 KiB
PHP
Raw Normal View History

2017-05-16 17:03:37 +00:00
#!/usr/bin/env php
2017-05-16 14:24:30 +00:00
<?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";
2017-06-03 08:35:21 +00:00
2017-05-16 14:24:30 +00:00
foreach($scriptErrors as $error) {
print " $error\n";
}
}
2017-06-03 08:35:21 +00:00
2017-05-16 14:24:30 +00:00
exit(1);
}
2017-05-16 17:03:37 +00:00
print "No errors were found\n";
exit(0);
2017-05-16 14:24:30 +00:00
class TestHelper {
public $errors = array();
2017-06-03 08:35:21 +00:00
2017-05-16 14:24:30 +00:00
/**
* Tests the files in a directory
*/
public function testDirectory($dir) {
$errors = array();
$jsonData = file_get_contents($dir . "/info.json");
$data = json_decode($jsonData, true);
2017-06-03 08:35:21 +00:00
2017-05-16 14:24:30 +00:00
if ($data["name"] == "") {
$errors[] = "No name was entered!";
}
2017-06-03 08:35:21 +00:00
$identifier = $data["identifier"];
if ($identifier == "") {
2017-05-16 14:24:30 +00:00
$errors[] = "No identifier was entered!";
2017-05-16 17:03:37 +00:00
} elseif (preg_match('/[^a-z0-9\-_]/', $identifier)) {
$errors[] = "Invalid charactes were found in identifier '$identifier'!";
2017-05-16 14:24:30 +00:00
}
2017-06-03 08:35:21 +00:00
2017-05-16 14:24:30 +00:00
if ($data["description"] == "") {
$errors[] = "No description was entered!";
}
2017-06-03 08:35:21 +00:00
2017-05-16 14:24:30 +00:00
$script = $data["script"];
if ($script == "") {
$errors[] = "No script was entered!";
} elseif (!file_exists($dir . "/" . $script)) {
$errors[] = "Script '$script' doesn't exist!";
}
2017-06-03 08:35:21 +00:00
2017-05-16 14:24:30 +00:00
if ($data["version"] == "") {
$errors[] = "No version was entered!";
}
2017-06-03 08:35:21 +00:00
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!";
}
}
}
}
2017-05-16 14:24:30 +00:00
if (count($errors) > 0) {
$this->errors[$dir] = $errors;
}
}
}