| 1 | <?php |
| 2 | /************************************************************* |
| 3 | # 076 License |
| 4 | |
| 5 | Copyright (c) テクニカル諏訪子 |
| 6 | |
| 7 | Permission is hereby granted to any person obtaining a copy of the software |
| 8 | Little Beast (the "Software") to use, modify, merge, copy, publish, distribute, |
| 9 | sublicense, and/or sell copies of the Software, subject to the following conditions: |
| 10 | |
| 11 | 1. **Origin Attribution**: |
| 12 | - You must not misrepresent the origin of the Software; you must not claim |
| 13 | you created the original Software. |
| 14 | - If the Software is used in a product, you must either: |
| 15 | a. Provide clear attribution in the product's documentation, user interface, |
| 16 | or other visible areas, **OR** |
| 17 | b. Pay the original developers a fee they specify in writing. |
| 18 | 2. **Usage Restriction**: |
| 19 | - The Software, or any derivative works, dependencies, or libraries |
| 20 | incorporating it, must not be used for censorship or to suppress freedom of |
| 21 | speech, expression, or creativity. Prohibited uses include, but are not |
| 22 | limited to: |
| 23 | - Censorship of so-called "hate speech", visuals, non-mainstream opinions, |
| 24 | ideas, or objective reality. |
| 25 | - Tools or systems designed to restrict access to information or |
| 26 | artistic works. |
| 27 | 3. **Notice Preservation**: |
| 28 | - This license and the above copyright notice must remain intact in all copies |
| 29 | of the source code. |
| 30 | |
| 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 32 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
| 33 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 34 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 35 | CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE |
| 36 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 37 | */ |
| 38 | require_once __DIR__.DIRECTORY_SEPARATOR.'/autoload.php'; |
| 39 | define('ROOT', realpath(__DIR__)); |
| 40 | require_once ROOT.'/config/config.php'; |
| 41 | require_once ROOT.'/util.php'; |
| 42 | if (!CURL_ENABLED) define('ACTIVITYPUB_ENABLED', false); |
| 43 | |
| 44 | mb_internal_encoding('UTF-8'); |
| 45 | header('Content-Type: text/plain; charset=UTF-8'); |
| 46 | |
| 47 | $testDirs = [ROOT.'/src/Site/Test', ROOT.'/src/Std/Test']; |
| 48 | $testFiles = []; |
| 49 | foreach ($testDirs as $d) $testFiles[] = glob($d.'/*.php'); |
| 50 | $testFiles = array_merge(...$testFiles); |
| 51 | |
| 52 | if (empty($testFiles)) { |
| 53 | echo "テストファイルではありません\n"; |
| 54 | exit(1); |
| 55 | } |
| 56 | |
| 57 | echo count($testFiles)."個テストファイルを実行中:\n"; |
| 58 | echo "------------------------------------------------\n"; |
| 59 | |
| 60 | $totalFiles = 0; |
| 61 | $successFiles = 0; |
| 62 | $failedFiles = []; |
| 63 | |
| 64 | foreach ($testFiles as $testFile) { |
| 65 | $filename = basename($testFile); |
| 66 | echo "{$filename}のテストを実行中... "; |
| 67 | |
| 68 | $totalFiles++; |
| 69 | |
| 70 | try { |
| 71 | ob_start(); |
| 72 | unset($test); |
| 73 | require $testFile; |
| 74 | $output = ob_get_clean(); |
| 75 | |
| 76 | echo "完成\n"; |
| 77 | echo $output; |
| 78 | echo "\n"; |
| 79 | |
| 80 | if (isset($test) && $test instanceof \Std\Lib\Tester && !$test->passed()) { |
| 81 | $failedFiles[] = ['file' => $filename, 'error' => 'テストが失敗・エラーで完了しました。', 'line' => null]; |
| 82 | } else { |
| 83 | $successFiles++; |
| 84 | } |
| 85 | } catch (\Throwable $e) { |
| 86 | $output = ob_get_clean(); |
| 87 | if (!empty($output)) { |
| 88 | echo $output."\n"; |
| 89 | } |
| 90 | echo "エラー: ".$e->getMessage()."\n"; |
| 91 | echo "ファイル: ".$e->getFile()." (行: ".$e->getLine().")\n\n"; |
| 92 | $failedFiles[] = [ |
| 93 | 'file' => $filename, |
| 94 | 'error' => $e->getMessage(), |
| 95 | 'line' => $e->getLine(), |
| 96 | ]; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | echo "\n"; |
| 101 | echo "テスト結果:\n"; |
| 102 | echo "------------------------------------------------\n"; |
| 103 | echo "テストファイル数: {$totalFiles}\n"; |
| 104 | echo "成功: {$successFiles}\n"; |
| 105 | echo "失敗: ".count($failedFiles)."\n"; |
| 106 | |
| 107 | if (!empty($failedFiles)) { |
| 108 | echo "\n失敗したテストファイル:\n"; |
| 109 | foreach ($failedFiles as $failed) { |
| 110 | echo "- {$failed['file']}".($failed['line'] !== null ? " (行: {$failed['line']})" : '').": {$failed['error']}\n"; |
| 111 | } |
| 112 | exit(1); |
| 113 | } |