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 '*.sql' -type f | xargs isutf8`;
47 $this->assertEquals('', $output);
48 $output = `find $root/src $root/tests -name '*.sh' -type f | xargs isutf8`;
49 $this->assertEquals('', $output);
50 $output = `find $root/src $root/tests -name '*.pl' -type f | xargs isutf8`;
51 $this->assertEquals('', $output);
55 * Ensure all scripts use Unix-style line endings
57 public function testUnixLineEndings()
59 $root = dirname(dirname(dirname(dirname(__FILE__))));
60 $output = `find $root/src $root/tests -name '*.php' -type f | xargs pcregrep -l '\r$'`;
61 $this->assertEquals('', $output);
62 $output = `find $root/src $root/tests -name '*.sql' -type f | xargs pcregrep -l '\r$'`;
63 $this->assertEquals('', $output);
64 $output = `find $root/src $root/tests -name '*.sh' -type f | xargs pcregrep -l '\r$'`;
65 $this->assertEquals('', $output);
66 $output = `find $root/src $root/tests -name '*.pl' -type f | xargs pcregrep -l '\r$'`;
67 $this->assertEquals('', $output);
71 * Ensure no scripts have SVN conflicts markers
73 public function testSVNConflicts()
75 $root = dirname(dirname(dirname(dirname(__FILE__))));
76 $output = `find $root/src $root/tests -type f | xargs grep -l '^<<<<<<'`;
77 $this->assertEquals('', $output);
78 $output = `find $root/src $root/tests -type f | xargs grep -l '^>>>>>>'`;
79 $this->assertEquals('', $output);
83 * Ensure no script has an empty last line
85 public function testEmptyLastLine()
87 $root = dirname(dirname(dirname(dirname(__FILE__))));
88 $output = `find $root/src $root/tests -name '*.php' -type f | while read i ; do [ -s \$i ] && [ -z "\$(tail -n 1 \$i)" ] && echo \$i ; done`;
89 $this->assertEquals('', $output);
93 * Validate syntax of gettextfiles
95 public function testGettextSyntax()
97 $root = dirname(dirname(dirname(dirname(__FILE__))));
98 $output = `cd $root/src ; ./utils/manage-translations.sh check 2>&1`;
99 $this->assertEquals('', $output);
105 // c-file-style: "bsd"