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 $output = `find $root/src $root/tests -name '*.php' -type f | xargs isutf8`;
45 $this->assertEquals('', $output);
46 $output = `find $root/src $root/tests -name '*.css' -type f | xargs isutf8`;
47 $this->assertEquals('', $output);
48 $output = `find $root/src $root/tests -name '*.sql' -type f | xargs isutf8`;
49 $this->assertEquals('', $output);
50 $output = `find $root/src $root/tests -name '*.sh' -type f | xargs isutf8`;
51 $this->assertEquals('', $output);
52 $output = `find $root/src $root/tests -name '*.pl' -type f | xargs isutf8`;
53 $this->assertEquals('', $output);
54 $output = `find $root/src $root/tests -name '*.tmpl' -type f | xargs isutf8`;
55 $this->assertEquals('', $output);
56 $output = `find $root/src $root/tests -name '*.xml' -type f | xargs isutf8`;
57 $this->assertEquals('', $output);
61 * Ensure all scripts use Unix-style line endings
63 public function testUnixLineEndings()
65 $root = dirname(dirname(dirname(dirname(__FILE__))));
66 // to see individual lines + line nums : find src tests -name '*.php' -type f | xargs pcregrep -n '\r$'
67 $output = `find $root/src $root/tests -name '*.php' -type f | xargs pcregrep -l '\r$'`;
68 $this->assertEquals('', $output);
69 $output = `find $root/src $root/tests -name '*.sql' -type f | xargs pcregrep -l '\r$'`;
70 $this->assertEquals('', $output);
71 $output = `find $root/src $root/tests -name '*.sh' -type f | xargs pcregrep -l '\r$'`;
72 $this->assertEquals('', $output);
73 $output = `find $root/src $root/tests -name '*.pl' -type f | xargs pcregrep -l '\r$'`;
74 $this->assertEquals('', $output);
78 * Ensure no scripts have SVN conflicts markers
80 public function testSVNConflicts()
82 $root = dirname(dirname(dirname(dirname(__FILE__))));
83 $output = `find $root/src $root/tests -type f | xargs grep -l '^<<<<<<'`;
84 $this->assertEquals('', $output);
85 $output = `find $root/src $root/tests -type f | xargs grep -l '^>>>>>>'`;
86 $this->assertEquals('', $output);
90 * Ensure no script has an empty last line
92 public function testEmptyLastLine()
94 $root = dirname(dirname(dirname(dirname(__FILE__))));
95 $output = `find $root/src $root/tests -name '*.php' -type f | while read i ; do [ -s \$i ] && [ -z "\$(tail -n 1 \$i)" ] && echo \$i ; done`;
96 $this->assertEquals('', $output);
100 * Validate syntax of gettextfiles
102 public function testGettextSyntax()
104 $root = dirname(dirname(dirname(dirname(__FILE__))));
105 $output = `cd $root/src ; ./utils/manage-translations.sh check 2>&1`;
106 $this->assertEquals('', $output);
112 // c-file-style: "bsd"