diff --git a/bin/pake b/bin/pake index d789444..7d51d14 100755 --- a/bin/pake +++ b/bin/pake @@ -4,13 +4,10 @@ function _pake_bin_init() { $loaded = false; - $_path = dirname(__FILE__); // php 5.2 compatibility - if (file_exists($_path.'/../../../../composer.json')) { + if (file_exists('composer.json')) { // looks like we are installed as dependency via composer - $project_dir = realpath($_path . '/../../../..'); - - $data = json_decode(file_get_contents($project_dir . DIRECTORY_SEPARATOR . 'composer.json'), true); + $data = json_decode(file_get_contents('composer.json'), true); if (isset($data['config']['vendor-dir'])) { $vendor_dir = $data['config']['vendor-dir']; @@ -18,27 +15,27 @@ function _pake_bin_init() $vendor_dir = 'vendor'; } - $autoload_file = $project_dir . '/' . $vendor_dir . '/autoload.php'; + $autoload_file = $vendor_dir . '/autoload.php'; if (file_exists($autoload_file)) { - require_once $autoload_file; + require_once($autoload_file); $loaded = true; } } - if (!$loaded and is_dir($_path . '/../vendor') and file_exists($_path . '/../vendor/autoload.php')) { + if (!$loaded and is_dir($__DIR__. '/../vendor') and file_exists($__DIR__. '/../vendor/autoload.php')) { // looks like we are in composer dev-environment - require_once realpath($_path . '/..').'/vendor/autoload.php'; + require_once(realpath($__DIR__. '/..').'/vendor/autoload.php'); $loaded = true; } if (!$loaded) { // fallback to custom autoloader - require_once realpath($_path . '/..').'/lib/pake/autoload.php'; + require_once('../lib/pake/autoload.php'); $loaded = true; } - require_once realpath($_path . '/..').'/lib/pake/cli_init.php'; + require_once('../lib/pake/cli_init.php'); $retval = pakeApp::get_instance()->run(); diff --git a/composer.json b/composer.json index 78f4d65..ea37a2e 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,8 @@ "ext-mbstring": "*" }, "require-dev": { - "simpletest/simpletest": "1.1.*" + "simpletest/simpletest": "1.1.*", + "phpunit/phpunit": "^7.5.18" }, "suggest": { "ext-bz2": "*", @@ -43,7 +44,12 @@ "simpletest/simpletest": "1.1.*" }, "autoload": { - "files": ["lib/pake/autoload.php"] + "classmap": ["lib/pake/"], + "files": ["lib/pake/pakeFunction.php"] + }, + "autoload-dev": { + "classmap": ["tests/", "lib/pake/"], + "files": ["lib/pake/pakeFunction.php"] }, "bin": ["bin/pake"] } diff --git a/pake.phar b/pake.phar new file mode 100755 index 0000000..8bababe Binary files /dev/null and b/pake.phar differ diff --git a/pakefile.php b/pakefile.php old mode 100644 new mode 100755 diff --git a/phar-composer-1.1.0.phar b/phar-composer-1.1.0.phar new file mode 100755 index 0000000..2123a7e Binary files /dev/null and b/phar-composer-1.1.0.phar differ diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..d61c6cd --- /dev/null +++ b/phpunit.xml @@ -0,0 +1 @@ + diff --git a/test/pakeGlobToRegexTest.php b/test/pakeGlobToRegexTest.php deleted file mode 100644 index 881f778..0000000 --- a/test/pakeGlobToRegexTest.php +++ /dev/null @@ -1,102 +0,0 @@ -assertTrue($this->match_glob('foo', 'foo')); - $this->assertTrue(!$this->match_glob('foo', 'foobar')); - - // * wildcard - $this->assertTrue($this->match_glob('foo.*', 'foo.')); - $this->assertTrue($this->match_glob('foo.*', 'foo.bar')); - $this->assertTrue(!$this->match_glob('foo.*', 'gfoo.bar')); - - // ? wildcard - $this->assertTrue($this->match_glob('foo.?p', 'foo.cp')); - $this->assertTrue(!$this->match_glob('foo.?p', 'foo.cd')); - - // .{alternation,or,something} - $this->assertTrue($this->match_glob('foo.{c,h}', 'foo.h')); - $this->assertTrue($this->match_glob('foo.{c,h}', 'foo.c')); - $this->assertTrue(!$this->match_glob('foo.{c,h}', 'foo.o')); - - // \escaping - $this->assertTrue($this->match_glob('foo.\\{c,h}\\*', 'foo.{c,h}*')); - $this->assertTrue(!$this->match_glob('foo.\\{c,h}\\*', 'foo.\\c')); - - // escape () - $this->assertTrue($this->match_glob('foo.(bar)', 'foo.(bar)')); - - // strict . rule fail - $this->assertTrue(!$this->match_glob('*.foo', '.file.foo')); - - // strict . rule match - $this->assertTrue($this->match_glob('.*.foo', '.file.foo')); - - // relaxed . rule - pakeGlobToRegex::setStrictLeadingDot(false); - $this->assertTrue($this->match_glob('*.foo', '.file.foo')); - pakeGlobToRegex::setStrictLeadingDot(true); - - // strict wildcard / fail - $this->assertTrue(!$this->match_glob('*.fo?', 'foo/file.fob')); - - // strict wildcard / match - $this->assertTrue($this->match_glob('*/*.fo?', 'foo/file.fob')); - - // relaxed wildcard / - pakeGlobToRegex::setStrictWildcardSlash(false); - $this->assertTrue($this->match_glob('*.fo?', 'foo/file.fob')); - pakeGlobToRegex::setStrictWildcardSlash(true); - - // more strict wildcard / fail - $this->assertTrue(!$this->match_glob('foo/*.foo', 'foo/.foo')); - - // more strict wildcard / match - $this->assertTrue($this->match_glob('foo/.f*', 'foo/.foo')); - - // relaxed wildcard / - pakeGlobToRegex::setStrictWildcardSlash(false); - $this->assertTrue($this->match_glob('*.foo', 'foo/.foo')); - pakeGlobToRegex::setStrictWildcardSlash(true); - - // properly escape + - $this->assertTrue($this->match_glob('f+.foo', 'f+.foo')); - $this->assertTrue(!$this->match_glob('f+.foo', 'ffff.foo')); - - // handle embedded \\n - $this->assertTrue($this->match_glob("foo\nbar", "foo\nbar")); - $this->assertTrue(!$this->match_glob("foo\nbar", "foobar")); - - // [abc] - $this->assertTrue($this->match_glob('test[abc]', 'testa')); - $this->assertTrue($this->match_glob('test[abc]', 'testb')); - $this->assertTrue($this->match_glob('test[abc]', 'testc')); - $this->assertTrue(!$this->match_glob('test[abc]', 'testd')); - - // escaping \$ - $this->assertTrue($this->match_glob('foo$bar.*', 'foo$bar.c')); - - // escaping ^ - $this->assertTrue($this->match_glob('foo^bar.*', 'foo^bar.c')); - - // escaping ^escaping | - $this->assertTrue($this->match_glob('foo|bar.*', 'foo|bar.c')); - - // {foo,{bar,baz}} - $this->assertTrue($this->match_glob('{foo,{bar,baz}}', 'foo')); - $this->assertTrue($this->match_glob('{foo,{bar,baz}}', 'bar')); - $this->assertTrue($this->match_glob('{foo,{bar,baz}}', 'baz')); - $this->assertTrue(!$this->match_glob('{foo,{bar,baz}}', 'foz')); - } - - private function match_glob($glob, $text) - { - $regex = pakeGlobToRegex::glob_to_regex($glob); - return preg_match($regex, $text); - } -} - -?> \ No newline at end of file diff --git a/test/pakePHPDocTest.php b/test/pakePHPDocTest.php deleted file mode 100644 index 51acfd2..0000000 --- a/test/pakePHPDocTest.php +++ /dev/null @@ -1,91 +0,0 @@ -assertEqual(2, count($desc)); - $this->assertEqual('', $desc[0]); - $this->assertEqual('', $desc[1]); - - $desc = pakePHPDoc::getDescriptions('pakePHPDocTest_test2'); - - $this->assertEqual(2, count($desc)); - $this->assertEqual('short description', $desc[0]); - $this->assertEqual('long description', $desc[1]); - - $desc = pakePHPDoc::getDescriptions('pakePHPDocTest_test3'); - - $this->assertEqual(2, count($desc)); - $this->assertEqual('short description still short description', $desc[0]); - $this->assertEqual('', $desc[1]); - - $desc = pakePHPDoc::getDescriptions('pakePHPDocTest_test4'); - - $this->assertEqual(2, count($desc)); - $this->assertEqual('short description', $desc[0]); - $this->assertEqual('', $desc[1]); - - $desc = pakePHPDoc::getDescriptions('pakePHPDocTest_test5'); - - $this->assertEqual(2, count($desc)); - $this->assertEqual('short description. still short description', $desc[0]); - $this->assertEqual('', $desc[1]); - - $desc = pakePHPDoc::getDescriptions('pakePHPDocTest_test6'); - - $this->assertEqual(2, count($desc)); - $this->assertEqual('short description. still short description', $desc[0]); - $this->assertEqual('', $desc[1]); - - $desc = pakePHPDoc::getDescriptions('pakePHPDocTest_test7'); - - $this->assertEqual(2, count($desc)); - $this->assertEqual('short description.', $desc[0]); - $this->assertEqual('long description', $desc[1]); - } -} - - - -function pakePHPDocTest_test1() {} - -/** - * short description - * - * long description - */ -function pakePHPDocTest_test2() {} - -/** - * short description - * still short description - */ -function pakePHPDocTest_test3() {} - -/** - * short description - * @something not a description - */ -function pakePHPDocTest_test4() {} - -/** - * short description. - * still short description - */ -function pakePHPDocTest_test5() {} - -/** -* short description. -* still short description -*/ -function pakePHPDocTest_test6() {} - -/** -* short description. -* -* long description -*/ -function pakePHPDocTest_test7() {} diff --git a/test/pakeTaskTest.php b/tests/PakeTaskTest.php similarity index 79% rename from test/pakeTaskTest.php rename to tests/PakeTaskTest.php index 8643be6..cb1accf 100644 --- a/test/pakeTaskTest.php +++ b/tests/PakeTaskTest.php @@ -1,8 +1,10 @@ array('queue'), 'queu' => array('queue'), 'queue' => array('queue'), 'qui' => array('quit'), 'quit' => array('quit') ); - $this->assertEqual($expected, $result); + $this->assertEquals($expected, $result); } } diff --git a/tests/autoload.php b/tests/autoload.php new file mode 100644 index 0000000..7803f54 --- /dev/null +++ b/tests/autoload.php @@ -0,0 +1,6 @@ +addPsr4("Your\\Test\\Namespace\\Here\\", __DIR__, true); +$classLoader->register(); diff --git a/test/finder_tests/dir1/dir2/dir3/file31 b/tests/finder_tests/dir1/dir2/dir3/file31 similarity index 100% rename from test/finder_tests/dir1/dir2/dir3/file31 rename to tests/finder_tests/dir1/dir2/dir3/file31 diff --git a/test/finder_tests/dir1/dir2/dir4/file41 b/tests/finder_tests/dir1/dir2/dir4/file41 similarity index 100% rename from test/finder_tests/dir1/dir2/dir4/file41 rename to tests/finder_tests/dir1/dir2/dir4/file41 diff --git a/test/finder_tests/dir1/dir2/file21.php b/tests/finder_tests/dir1/dir2/file21.php similarity index 100% rename from test/finder_tests/dir1/dir2/file21.php rename to tests/finder_tests/dir1/dir2/file21.php diff --git a/test/finder_tests/dir1/dir2/file22 b/tests/finder_tests/dir1/dir2/file22 similarity index 100% rename from test/finder_tests/dir1/dir2/file22 rename to tests/finder_tests/dir1/dir2/file22 diff --git a/test/finder_tests/dir1/dir2/file23 b/tests/finder_tests/dir1/dir2/file23 similarity index 100% rename from test/finder_tests/dir1/dir2/file23 rename to tests/finder_tests/dir1/dir2/file23 diff --git a/test/finder_tests/dir1/dir2/file24 b/tests/finder_tests/dir1/dir2/file24 similarity index 100% rename from test/finder_tests/dir1/dir2/file24 rename to tests/finder_tests/dir1/dir2/file24 diff --git a/test/finder_tests/dir1/file11 b/tests/finder_tests/dir1/file11 similarity index 100% rename from test/finder_tests/dir1/file11 rename to tests/finder_tests/dir1/file11 diff --git a/test/finder_tests/dir1/file12.php b/tests/finder_tests/dir1/file12.php similarity index 100% rename from test/finder_tests/dir1/file12.php rename to tests/finder_tests/dir1/file12.php diff --git a/test/finder_tests/dir1/file13 b/tests/finder_tests/dir1/file13 similarity index 100% rename from test/finder_tests/dir1/file13 rename to tests/finder_tests/dir1/file13 diff --git a/test/finder_tests/file1 b/tests/finder_tests/file1 similarity index 100% rename from test/finder_tests/file1 rename to tests/finder_tests/file1 diff --git a/test/finder_tests/file2.txt b/tests/finder_tests/file2.txt similarity index 100% rename from test/finder_tests/file2.txt rename to tests/finder_tests/file2.txt diff --git a/test/pakeFinderTest.php b/tests/pakeFinderTest.php similarity index 84% rename from test/pakeFinderTest.php rename to tests/pakeFinderTest.php index 7ab739e..fdf2bc3 100644 --- a/test/pakeFinderTest.php +++ b/tests/pakeFinderTest.php @@ -1,6 +1,7 @@ assertIsA($finder, 'pakeFinder'); + $this->assertInstanceOf('pakeFinder', $finder); $finder = pakeFinder::type('file')->name('*.php')->prune('*.svn'); - $this->assertTrue($finder->in($this->dir), 'pakeFinder'); + $this->assertEquals(2, count($finder->in($this->dir))); } public function test_args_as_array() @@ -24,13 +25,13 @@ public function test_args_as_array() $files2 = pakeFinder::type('any')->name(array('*.php', '*.txt'))->prune('.svn')->in($this->dir); sort($files1); sort($files2); - $this->assertEqual($files1, $files2); + $this->assertEquals($files1, $files2); } public function test_file_and_directory() { $finder = pakeFinder::type('any'); - $this->assertIsA($finder, 'pakeFinder'); + $this->assertInstanceOf('pakeFinder', $finder); $files_and_directories = pakeFinder::type('any')->prune('.svn')->in($this->dir); @@ -41,19 +42,19 @@ public function test_file_and_directory() $b = $files_and_directories; sort($a); sort($b); - $this->assertEqual($a, $b); + $this->assertEquals($a, $b); $directories1 = pakeFinder::type('dir')->prune('.svn')->in($this->dir); - $this->assertEqual($directories, $directories1); + $this->assertEquals($directories, $directories1); $files1 = pakeFinder::type('file')->prune('.svn')->in($this->dir); - $this->assertEqual($files, $files1); + $this->assertEquals($files, $files1); } public function test_full() { $files = pakeFinder::type('file')->name('/^file/')->size('> 0K')->size('< 10K')->prune('/^dir*/')->prune('.svn')->in($this->dir); - $this->assertEqual(1, count($files)); + $this->assertEquals(1, count($files)); $finder = pakeFinder::type('file'); $finder->name('/^file/'); @@ -62,13 +63,13 @@ public function test_full() $finder->prune('/^dir*/'); $finder->prune('.svn'); $files = $finder->in($this->dir); - $this->assertEqual(1, count($files)); + $this->assertEquals(1, count($files)); } public function test_name() { $files = pakeFinder::type('any')->name('*.php')->prune('.svn')->in($this->dir); - $this->assertEqual(2, count($files)); + $this->assertEquals(2, count($files)); $ok = true; foreach ($files as $file) { @@ -77,7 +78,7 @@ public function test_name() $this->assertTrue($ok); $files = pakeFinder::type('any')->name('*.php', '*.txt')->prune('.svn')->in($this->dir); - $this->assertEqual(3, count($files)); + $this->assertEquals(3, count($files)); $ok = true; foreach ($files as $file) { @@ -86,7 +87,7 @@ public function test_name() $this->assertTrue($ok); $files = pakeFinder::type('any')->name('*.php')->name('*.txt')->prune('.svn')->in($this->dir); - $this->assertEqual(3, count($files)); + $this->assertEquals(3, count($files)); $ok = true; foreach ($files as $file) { @@ -95,7 +96,7 @@ public function test_name() $this->assertTrue($ok); $files = pakeFinder::type('any')->name('/\.php$/', '/\.txt$/')->prune('.svn')->in($this->dir); - $this->assertEqual(3, count($files)); + $this->assertEquals(3, count($files)); $ok = true; foreach ($files as $file) { @@ -104,8 +105,7 @@ public function test_name() $this->assertTrue($ok); $files = pakeFinder::type('any')->name('file12.php')->prune('.svn')->in($this->dir); - $this->assertEqual(1, count($files)); - $this->assertTrue('file1', $files[0]); + $this->assertEquals(1, count($files)); } public function test_relative() @@ -151,7 +151,7 @@ public function test_not_name() $files3 = array_merge($files, $files1); sort($files3); sort($files2); - $this->assertEqual($files3, $files2); + $this->assertEquals($files3, $files2); $files = pakeFinder::type('file')->name('file2*')->not_name('*.php')->prune('.svn')->relative()->in($this->dir); $ok = true; @@ -224,13 +224,13 @@ public function test_prune() public function test_size() { $files = pakeFinder::type('file')->size('> 100K')->prune('.svn')->in($this->dir); - $this->assertEqual(array(), $files); + $this->assertEquals(array(), $files); $files = pakeFinder::type('file')->size('> 2K')->prune('.svn')->in($this->dir); - $this->assertEqual(1, count($files)); + $this->assertEquals(1, count($files)); $files = pakeFinder::type('file')->size('> 2K')->size('< 3K')->prune('.svn')->in($this->dir); - $this->assertEqual(0, count($files)); + $this->assertEquals(0, count($files)); } public function test_in() @@ -241,11 +241,11 @@ public function test_in() sort($files); $files3 = array_merge($files1, $files2); sort($files3); - $this->assertEqual($files3, $files); + $this->assertEquals($files3, $files); $files4 = pakeFinder::type('file')->prune('.svn')->in(array($this->dir.'/dir1/dir2/dir3', $this->dir.'/dir1/dir2/dir4')); sort($files4); - $this->assertEqual($files4, $files); + $this->assertEquals($files4, $files); $files = pakeFinder::type('file')->prune('.svn')->in($this->dir.'/dir1/dir2/dir3', $this->dir.'/dir1/dir2/dir4', $this->dir.'/dir1/dir2/dir4'); $files1 = pakeFinder::type('file')->prune('.svn')->in($this->dir.'/dir1/dir2/dir3'); @@ -253,7 +253,7 @@ public function test_in() sort($files); $files3 = array_merge($files1, $files2); sort($files3); - $this->assertEqual($files3, $files); + $this->assertEquals($files3, $files); try { @@ -269,13 +269,13 @@ public function test_clone() { $finder = pakeFinder::type('any')->name('file*')->prune('.svn'); $finder1 = clone $finder; - $this->assertTrue($finder->in($this->dir), implode(', ', $finder1->in($this->dir))); + $this->assertEquals($finder->in($this->dir), $finder1->in($this->dir)); $finder->size('>1K'); - $this->assertNotEqual($finder->in($this->dir), $finder1->in($this->dir)); + $this->assertNotEquals($finder->in($this->dir), $finder1->in($this->dir)); $finder1->size('>1K'); - $this->assertEqual($finder->in($this->dir), $finder1->in($this->dir)); + $this->assertEquals($finder->in($this->dir), $finder1->in($this->dir)); } public function test_exec() @@ -287,7 +287,7 @@ function mytest($dir, $entry) $files = pakeFinder::type('any')->exec('mytest')->prune('.svn')->in($this->dir); $files1 = pakeFinder::type('any')->prune('.svn')->in($this->dir); - $this->assertEqual($files, $files1); + $this->assertEquals($files, $files1); function mytest2($dir, $entry) { @@ -296,11 +296,11 @@ function mytest2($dir, $entry) $files = pakeFinder::type('any')->exec('mytest2')->prune('.svn')->in($this->dir); $files1 = pakeFinder::type('any')->name('*.php')->prune('.svn')->in($this->dir); - $this->assertEqual($files, $files1); + $this->assertEquals($files, $files1); $files = pakeFinder::type('any')->exec(array($this, 'mytest3'))->prune('.svn')->in($this->dir); $files1 = pakeFinder::type('any')->prune('.svn')->in($this->dir); - $this->assertEqual($files, $files1); + $this->assertEquals($files, $files1); } public function mytest3($dir, $entry) @@ -311,24 +311,24 @@ public function mytest3($dir, $entry) public function test_pattern() { $files = pakeFinder::type('file')->pattern('dir1/*/*')->in($this->dir); - $this->assertEqual(4, count($files)); + $this->assertEquals(4, count($files)); $files = pakeFinder::type('dir')->pattern('dir1/*/*')->in($this->dir); - $this->assertEqual(2, count($files)); + $this->assertEquals(2, count($files)); $files = pakeFinder::type('any')->pattern('dir1/**/file41')->in($this->dir); - $this->assertEqual(1, count($files)); + $this->assertEquals(1, count($files)); $files = pakeFinder::type('any')->pattern('dir1/**/dir3/')->in($this->dir); - $this->assertEqual(1, count($files)); + $this->assertEquals(1, count($files)); $files = pakeFinder::type('any')->pattern('dir1/**/*')->in($this->dir); - $this->assertEqual(8, count($files)); + $this->assertEquals(8, count($files)); $files = pakeFinder::type('any')->pattern('dir1/**/*')->not_pattern('dir1/*/dir?')->in($this->dir); - $this->assertEqual(6, count($files)); + $this->assertEquals(6, count($files)); } } -?> \ No newline at end of file +?> diff --git a/test/pakeFunctionTest.php b/tests/pakeFunctionTest.php similarity index 90% rename from test/pakeFunctionTest.php rename to tests/pakeFunctionTest.php index 1501b5b..012968c 100644 --- a/test/pakeFunctionTest.php +++ b/tests/pakeFunctionTest.php @@ -1,6 +1,8 @@ test_dir.DIRECTORY_SEPARATOR.$test_file_name; $replaced = file_get_contents($test_file); - $this->assertEqual('hello world', $replaced); + $this->assertEquals('hello world', $replaced); } public function test_pake_replace_tokens_finder() @@ -60,7 +62,7 @@ public function test_pake_replace_tokens_finder() foreach ($test_file_names as $test_file_name) { $test_file = $this->test_dir.DIRECTORY_SEPARATOR.$test_file_name; $replaced = file_get_contents($test_file); - $this->assertEqual('hello world', $replaced); + $this->assertEquals('hello world', $replaced); } } } diff --git a/test/pakeGetoptTest.php b/tests/pakeGetoptTest.php similarity index 61% rename from test/pakeGetoptTest.php rename to tests/pakeGetoptTest.php index f143d81..edb0bcd 100644 --- a/test/pakeGetoptTest.php +++ b/tests/pakeGetoptTest.php @@ -1,6 +1,8 @@ assertPattern('/You cannot get a value for a NO_ARGUMENT/', $e->getMessage()); + $this->assertEquals('pakeGetopt: You cannot get a value for a NO_ARGUMENT option.', $e->getMessage()); } $g->parse('-t'); @@ -29,7 +31,7 @@ public function test_simple() } catch (pakeException $e) { - $this->assertPattern('/unrecognized option \-v/', $e->getMessage()); + $this->assertEquals('pakeGetopt: unrecognized option -v.', $e->getMessage()); } } @@ -41,16 +43,16 @@ public function test_arguments() $g = new pakeGetopt($options); $g->parse('--test toto with arguments'); - $this->assertEqual(array('toto', 'with', 'arguments'), $g->get_arguments()); + $this->assertEquals(array('toto', 'with', 'arguments'), $g->get_arguments()); $g->parse('toto with arguments'); - $this->assertEqual(array('toto', 'with', 'arguments'), $g->get_arguments()); + $this->assertEquals(array('toto', 'with', 'arguments'), $g->get_arguments()); $g->parse('-- --toto with arguments'); - $this->assertEqual(array('--toto', 'with', 'arguments'), $g->get_arguments()); + $this->assertEquals(array('--toto', 'with', 'arguments'), $g->get_arguments()); $g->parse('-t -- --toto with arguments'); - $this->assertEqual(array('--toto', 'with', 'arguments'), $g->get_arguments()); + $this->assertEquals(array('--toto', 'with', 'arguments'), $g->get_arguments()); } public function test_options() @@ -74,44 +76,44 @@ public function test_options() } $g->parse('--test=Toto'); - $this->assertEqual('Toto', $g->has_option('test')); - $this->assertEqual('Toto', $g->get_option('test')); + $this->assertEquals(true, $g->has_option('test')); + $this->assertEquals('Toto', $g->get_option('test')); $g->parse('--test="Foo bar"'); - $this->assertEqual('Foo bar', $g->get_option('test')); + $this->assertEquals('Foo bar', $g->get_option('test')); $g->parse('--test=\'Foo bar bar\''); - $this->assertEqual('Foo bar bar', $g->get_option('test')); + $this->assertEquals('Foo bar bar', $g->get_option('test')); $g->parse('-pr'); $this->assertTrue($g->has_option('opt1')); $this->assertTrue($g->has_option('opt2')); $g->parse('-tFoo'); - $this->assertEqual('Foo', $g->get_option('test')); + $this->assertEquals('Foo', $g->get_option('test')); $g->parse('-t Foo'); - $this->assertEqual('Foo', $g->get_option('test')); + $this->assertEquals('Foo', $g->get_option('test')); $g->parse('-o Foo'); - $this->assertEqual('Foo', $g->get_option('opt')); + $this->assertEquals('Foo', $g->get_option('opt')); $g->parse('-o -p'); $this->assertTrue($g->has_option('opt')); $this->assertTrue($g->has_option('opt1')); $g->parse('-t "Foo bar"'); - $this->assertEqual('Foo bar', $g->get_option('test')); + $this->assertEquals('Foo bar', $g->get_option('test')); $g->parse('-t"Foo bar"'); - $this->assertEqual('Foo bar', $g->get_option('test')); + $this->assertEquals('Foo bar', $g->get_option('test')); $g->parse('-t\'Foo bar\''); - $this->assertEqual('Foo bar', $g->get_option('test')); + $this->assertEquals('Foo bar', $g->get_option('test')); $g->parse('-t"Foo bar" --test1="Another test"'); - $this->assertEqual('Foo bar', $g->get_option('test')); - $this->assertEqual('Another test', $g->get_option('test1')); + $this->assertEquals('Foo bar', $g->get_option('test')); + $this->assertEquals('Another test', $g->get_option('test1')); $g->parse('-o'); $this->assertTrue($g->get_option('opt')); @@ -120,9 +122,9 @@ public function test_options() $this->assertTrue($g->get_option('opt')); $g->parse('--opt="foo"'); - $this->assertEqual('foo', $g->get_option('opt')); - $this->assertFalse($g->get_option('test')); + $this->assertEquals('foo', $g->get_option('opt')); + $this->assertEquals('', $g->get_option('test')); } } -?> \ No newline at end of file +?> diff --git a/tests/pakeGlobToRegexTest.php b/tests/pakeGlobToRegexTest.php new file mode 100644 index 0000000..a0987f5 --- /dev/null +++ b/tests/pakeGlobToRegexTest.php @@ -0,0 +1,104 @@ +assertEquals(1, $this->match_glob('foo', 'foo')); + $this->assertEquals(0, $this->match_glob('foo', 'foobar')); + + // * wildcard + $this->assertEquals(1, $this->match_glob('foo.*', 'foo.')); + $this->assertEquals(1, $this->match_glob('foo.*', 'foo.bar')); + $this->assertEquals(0, $this->match_glob('foo.*', 'gfoo.bar')); + + // ? wildcard + $this->assertEquals(1, $this->match_glob('foo.?p', 'foo.cp')); + $this->assertEquals(0, $this->match_glob('foo.?p', 'foo.cd')); + + // .{alternation,or,something} + $this->assertEquals(1, $this->match_glob('foo.{c,h}', 'foo.h')); + $this->assertEquals(1, $this->match_glob('foo.{c,h}', 'foo.c')); + $this->assertEquals(0, $this->match_glob('foo.{c,h}', 'foo.o')); + + // \escaping + $this->assertEquals(1, $this->match_glob('foo.\\{c,h}\\*', 'foo.{c,h}*')); + $this->assertEquals(0, $this->match_glob('foo.\\{c,h}\\*', 'foo.\\c')); + + // escape () + $this->assertEquals(1, $this->match_glob('foo.(bar)', 'foo.(bar)')); + + // strict . rule fail + $this->assertEquals(0, $this->match_glob('*.foo', '.file.foo')); + + // strict . rule match + $this->assertEquals(1, $this->match_glob('.*.foo', '.file.foo')); + + // relaxed . rule + pakeGlobToRegex::setStrictLeadingDot(false); + $this->assertEquals(1, $this->match_glob('*.foo', '.file.foo')); + pakeGlobToRegex::setStrictLeadingDot(true); + + // strict wildcard / fail + $this->assertEquals(0, $this->match_glob('*.fo?', 'foo/file.fob')); + + // strict wildcard / match + $this->assertEquals(1, $this->match_glob('*/*.fo?', 'foo/file.fob')); + + // relaxed wildcard / + pakeGlobToRegex::setStrictWildcardSlash(false); + $this->assertEquals(1, $this->match_glob('*.fo?', 'foo/file.fob')); + pakeGlobToRegex::setStrictWildcardSlash(true); + + // more strict wildcard / fail + $this->assertEquals(0, $this->match_glob('foo/*.foo', 'foo/.foo')); + + // more strict wildcard / match + $this->assertEquals(1, $this->match_glob('foo/.f*', 'foo/.foo')); + + // relaxed wildcard / + pakeGlobToRegex::setStrictWildcardSlash(false); + $this->assertEquals(1, $this->match_glob('*.foo', 'foo/.foo')); + pakeGlobToRegex::setStrictWildcardSlash(true); + + // properly escape + + $this->assertEquals(1, $this->match_glob('f+.foo', 'f+.foo')); + $this->assertEquals(0, $this->match_glob('f+.foo', 'ffff.foo')); + + // handle embedded \\n + $this->assertEquals(1, $this->match_glob("foo\nbar", "foo\nbar")); + $this->assertEquals(0, $this->match_glob("foo\nbar", "foobar")); + + // [abc] + $this->assertEquals(1, $this->match_glob('test[abc]', 'testa')); + $this->assertEquals(1, $this->match_glob('test[abc]', 'testb')); + $this->assertEquals(1, $this->match_glob('test[abc]', 'testc')); + $this->assertEquals(0, $this->match_glob('test[abc]', 'testd')); + + // escaping \$ + $this->assertEquals(1, $this->match_glob('foo$bar.*', 'foo$bar.c')); + + // escaping ^ + $this->assertEquals(1, $this->match_glob('foo^bar.*', 'foo^bar.c')); + + // escaping ^escaping | + $this->assertEquals(1, $this->match_glob('foo|bar.*', 'foo|bar.c')); + + // {foo,{bar,baz}} + $this->assertEquals(1, $this->match_glob('{foo,{bar,baz}}', 'foo')); + $this->assertEquals(1, $this->match_glob('{foo,{bar,baz}}', 'bar')); + $this->assertEquals(1, $this->match_glob('{foo,{bar,baz}}', 'baz')); + $this->assertEquals(0, $this->match_glob('{foo,{bar,baz}}', 'foz')); + } + + private function match_glob($glob, $text) + { + $regex = pakeGlobToRegex::glob_to_regex($glob); + return preg_match($regex, $text); + } +} + +?> diff --git a/test/pakeNumberCompareTest.php b/tests/pakeNumberCompareTest.php similarity index 94% rename from test/pakeNumberCompareTest.php rename to tests/pakeNumberCompareTest.php index be92a74..13371cb 100644 --- a/test/pakeNumberCompareTest.php +++ b/tests/pakeNumberCompareTest.php @@ -1,6 +1,8 @@ \ No newline at end of file +?> diff --git a/tests/pakePHPDocTest.php b/tests/pakePHPDocTest.php new file mode 100644 index 0000000..8473712 --- /dev/null +++ b/tests/pakePHPDocTest.php @@ -0,0 +1,93 @@ +assertEquals(2, count($desc)); + $this->assertEquals('', $desc[0]); + $this->assertEquals('', $desc[1]); + + $desc = pakePHPDoc::getDescriptions('pakePHPDocTest_test2'); + + $this->assertEquals(2, count($desc)); + $this->assertEquals('short description', $desc[0]); + $this->assertEquals('long description', $desc[1]); + + $desc = pakePHPDoc::getDescriptions('pakePHPDocTest_test3'); + + $this->assertEquals(2, count($desc)); + $this->assertEquals('short description still short description', $desc[0]); + $this->assertEquals('', $desc[1]); + + $desc = pakePHPDoc::getDescriptions('pakePHPDocTest_test4'); + + $this->assertEquals(2, count($desc)); + $this->assertEquals('short description', $desc[0]); + $this->assertEquals('', $desc[1]); + + $desc = pakePHPDoc::getDescriptions('pakePHPDocTest_test5'); + + $this->assertEquals(2, count($desc)); + $this->assertEquals('short description. still short description', $desc[0]); + $this->assertEquals('', $desc[1]); + + $desc = pakePHPDoc::getDescriptions('pakePHPDocTest_test6'); + + $this->assertEquals(2, count($desc)); + $this->assertEquals('short description. still short description', $desc[0]); + $this->assertEquals('', $desc[1]); + + $desc = pakePHPDoc::getDescriptions('pakePHPDocTest_test7'); + + $this->assertEquals(2, count($desc)); + $this->assertEquals('short description.', $desc[0]); + $this->assertEquals('long description', $desc[1]); + } +} + + + +function pakePHPDocTest_test1() {} + +/** + * short description + * + * long description + */ +function pakePHPDocTest_test2() {} + +/** + * short description + * still short description + */ +function pakePHPDocTest_test3() {} + +/** + * short description + * @something not a description + */ +function pakePHPDocTest_test4() {} + +/** + * short description. + * still short description + */ +function pakePHPDocTest_test5() {} + +/** +* short description. +* still short description +*/ +function pakePHPDocTest_test6() {} + +/** +* short description. +* +* long description +*/ +function pakePHPDocTest_test7() {}