Skip to content

Commit b96b848

Browse files
committed
Test executable files
1 parent 5bdd7e5 commit b96b848

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

tests/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
error_reporting(E_ALL);
44

5+
define('GETTEXT_LANGUAGES_TESTROOTDIR', str_replace(DIRECTORY_SEPARATOR, '/', dirname(__DIR__)));
56
define('GETTEXT_LANGUAGES_TESTDIR', str_replace(DIRECTORY_SEPARATOR, '/', __DIR__));
67

78
$cmd = defined('PHP_BINARY') && PHP_BINARY ? escapeshellarg(PHP_BINARY) : 'php';

tests/test/ExecutableFilesTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Gettext\Languages\Test;
4+
5+
class ExecutableFilesTest extends TestCase
6+
{
7+
public function testExecutableFiles()
8+
{
9+
if (DIRECTORY_SEPARATOR === '\\') {
10+
$this->markTestSkipped('Testing executable files requires a Posix environment');
11+
}
12+
$expected = array(
13+
'bin/export-plural-rules',
14+
);
15+
$actual = $this->listExecutableFiles();
16+
$this->assertSame($expected, $actual);
17+
}
18+
19+
/**
20+
* @return string[]
21+
*/
22+
private function listExecutableFiles()
23+
{
24+
$rc = -1;
25+
$output = array();
26+
exec('find ' . escapeshellarg(GETTEXT_LANGUAGES_TESTROOTDIR) . ' -type f -executable 2>&1', $output, $rc);
27+
if ($rc !== 0) {
28+
$this->markTestSkipped('Failed to retrieve the list of executable files (' . trim(implode("\n", $output)) . ')');
29+
}
30+
$result = array_map(
31+
function ($file) {
32+
return substr($file, strlen(GETTEXT_LANGUAGES_TESTROOTDIR) + 1);
33+
},
34+
$output
35+
);
36+
$result = array_filter(
37+
$result,
38+
function ($file) {
39+
return $file !== '' && strpos($file, '.git/') !== 0 && strpos($file, 'vendor/') !== 0;
40+
}
41+
);
42+
sort($result);
43+
44+
return $result;
45+
}
46+
}

0 commit comments

Comments
 (0)