3 require_once 'PHPUnit/Framework/TestCase.php';
9 * @author Alain Peyrat <aljeux@free.fr>
10 * @copyright 2009 Alain Peyrat. All rights reserved.
11 * @license http://www.opensource.org/licenses/gpl-license.php GPL License
13 class Syntax_Tests extends PHPUnit_Framework_TestCase
16 * First, make sure pcregrep is installed
18 public function testPcRegrepInstalled()
20 $output = `type pcregrep >/dev/null; echo $?`;
23 $output = `type pcregrep`;
24 $this->fail('You should probably install "pcregrep" : `type pcregrep` reports "'.$output);
29 * First, make sure it is run from inside the tests/ subdir
31 public function testPath()
33 $output = `ls ../src >/dev/null; echo $?`;
36 $output = `ls ../src`;
37 $this->fail('Must be run from inside the "tests/" subdir : `ls ../src` reports "'.$output);
41 * Validate all php code with php -l.
43 public function testPhpSyntax()
45 $output = `cd .. ; find src tests -name '*.php' -type f -exec php -l {} \; | grep -v '^No syntax errors detected'`;
46 $this->assertEquals('', $output);
50 * Validate all scripts with isutf8.
52 public function testUTF8Chars()
54 // Skip the wiki part which is not UTF-8 encoded.
55 $output = `cd .. ; find src tests -name '*.php' -not -path 'src/plugins/wiki/www/*' -type f | xargs isutf8`;
56 $this->assertEquals('', $output);
57 $output = `cd .. ; find src tests -name '*.sql' -type f | xargs isutf8`;
58 $this->assertEquals('', $output);
59 $output = `cd .. ; find src tests -name '*.sh' -type f | xargs isutf8`;
60 $this->assertEquals('', $output);
61 $output = `cd .. ; find src tests -name '*.pl' -type f | xargs isutf8`;
62 $this->assertEquals('', $output);
66 * Ensure all scripts use Unix-style line endings
68 public function testUnixLineEndings()
70 $output = `cd .. ; find src tests -name '*.php' -type f | xargs pcregrep -l '\r$'`;
71 $this->assertEquals('', $output);
72 $output = `cd .. ; find src tests -name '*.sql' -type f | xargs pcregrep -l '\r$'`;
73 $this->assertEquals('', $output);
74 $output = `cd .. ; find src tests -name '*.sh' -type f | xargs pcregrep -l '\r$'`;
75 $this->assertEquals('', $output);
76 $output = `cd .. ; find src tests -name '*.pl' -type f | xargs pcregrep -l '\r$'`;
77 $this->assertEquals('', $output);
81 * Ensure no script has an empty last line
83 public function testEmptyLastLine()
85 $output = `cd .. ; find src tests -name '*.php' -type f | while read i ; do [ -z "\$(tail -n 1 \$i)" ] && echo \$i ; done`;
86 $this->assertEquals('', $output);
92 // c-file-style: "bsd"