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 * Validate all php code with php -l.
31 public function testPhpSyntax()
33 $root = dirname(dirname(dirname(dirname(__FILE__))));
34 $output = `find $root/src $root/tests -name '*.php' -type f -exec php -l {} \; | grep -v '^No syntax errors detected'`;
35 $this->assertEquals('', $output);
39 * Validate all scripts with isutf8.
41 public function testUTF8Chars()
43 $root = dirname(dirname(dirname(dirname(__FILE__))));
44 // We don't pass syntax tests on 3rd party libraries in src/lib/vendor
45 $exclude_third_party_libs="-path '$root/src/lib/vendor' -prune -o ";
46 $output = `find $root/src $root/tests $exclude_third_party_libs -name '*.php' -type f -print | xargs isutf8`;
47 $this->assertEquals('', $output);
48 $output = `find $root/src $root/tests $exclude_third_party_libs -name '*.css' -type f -print | xargs isutf8`;
49 $this->assertEquals('', $output);
50 $output = `find $root/src $root/tests $exclude_third_party_libs -name '*.sql' -type f -print | xargs isutf8`;
51 $this->assertEquals('', $output);
52 $output = `find $root/src $root/tests $exclude_third_party_libs -name '*.sh' -type f -print | xargs isutf8`;
53 $this->assertEquals('', $output);
54 $output = `find $root/src $root/tests $exclude_third_party_libs -name '*.pl' -type f -print | xargs isutf8`;
55 $this->assertEquals('', $output);
56 $output = `find $root/src $root/tests $exclude_third_party_libs -name '*.tmpl' -type f -print | xargs isutf8`;
57 $this->assertEquals('', $output);
58 $output = `find $root/src $root/tests $exclude_third_party_libs -name '*.xml' -type f -print | xargs isutf8`;
59 $this->assertEquals('', $output);
63 * Ensure all scripts use Unix-style line endings
65 public function testUnixLineEndings()
67 $root = dirname(dirname(dirname(dirname(__FILE__))));
68 // to see individual lines + line nums : find src tests -name '*.php' -type f | xargs pcregrep -n '\r$'
69 $output = `find $root/src $root/tests -name '*.php' -type f | xargs pcregrep -l '\r$'`;
70 $this->assertEquals('', $output);
71 $output = `find $root/src $root/tests -name '*.sql' -type f | xargs pcregrep -l '\r$'`;
72 $this->assertEquals('', $output);
73 $output = `find $root/src $root/tests -name '*.sh' -type f | xargs pcregrep -l '\r$'`;
74 $this->assertEquals('', $output);
75 $output = `find $root/src $root/tests -name '*.pl' -type f | xargs pcregrep -l '\r$'`;
76 $this->assertEquals('', $output);
80 * Ensure no scripts have SVN conflicts markers
82 public function testSVNConflicts()
84 $root = dirname(dirname(dirname(dirname(__FILE__))));
85 $output = `find $root/src $root/tests -type f | xargs grep -l '^<<<<<<'`;
86 $this->assertEquals('', $output);
87 $output = `find $root/src $root/tests -type f | xargs grep -l '^>>>>>>'`;
88 $this->assertEquals('', $output);
92 * Ensure no script has an empty last line
94 public function testEmptyLastLine()
96 $root = dirname(dirname(dirname(dirname(__FILE__))));
97 // We don't pass syntax tests on 3rd party libraries in src/lib/vendor
98 $exclude_third_party_libs="-path '$root/src/lib/vendor' -prune -o ";
99 $output = `find $root/src $root/tests $exclude_third_party_libs -name '*.php' -type f -print | while read i ; do [ -s \$i ] && [ -z "\$(tail -n 1 \$i)" ] && echo \$i ; done`;
100 $this->assertEquals('', $output);
104 * Validate syntax of gettextfiles
106 public function testGettextSyntax()
108 $root = dirname(dirname(dirname(dirname(__FILE__))));
109 $output = `cd $root/src ; ./utils/manage-translations.sh check 2>&1`;
110 $this->assertEquals('', $output);
116 // c-file-style: "bsd"