# how to test using run-tests?

- Thread: https://externals.io/message/34497
- Original archive: https://news-web.php.net/php.internals/34497
- Started by Gregory Beaver on 2008-01-05T01:05:16+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #34497 — Gregory Beaver — 2008-01-05T01:05:16+00:00

URL: https://externals.io/message/34497#34497

Hi,

I'm trying to figure out how to test a feature in the phar extension
that requires the executable test file to be an actual phar archive. 
This would be possible if there was some way to load the --FILE--
section from an external file.  Would anyone object to adding a new
section to the .phpt format "--FILE_EXTERNAL--" that simply takes a
relative path to the file to use as the contents for the test?

The attached patch adds this section and also fixes a minor bug in the
handling of POST_RAW that inserts a spurious \n

Greg

---

## #34498 — Gregory Beaver — 2008-01-05T02:50:55+00:00

URL: https://externals.io/message/34497#34498 · In reply to: #34497

Gregory Beaver wrote:
> Hi,
> 
> I'm trying to figure out how to test a feature in the phar extension
> that requires the executable test file to be an actual phar archive. 
> This would be possible if there was some way to load the --FILE--
> section from an external file.  Would anyone object to adding a new
> section to the .phpt format "--FILE_EXTERNAL--" that simply takes a
> relative path to the file to use as the contents for the test?
> 
> The attached patch adds this section and also fixes a minor bug in the
> handling of POST_RAW that inserts a spurious \n

Hi again,

After a bit more thought, I revised things.  The attached patch is
better - it simply copies the external file and saves it as the
$test_file.  I also failed to mention that this is against PHP_5_3, but
obviously could be ported to HEAD pretty much unmodified

Greg

---

## #34499 — Gregory Beaver — 2008-01-05T03:25:00+00:00

URL: https://externals.io/message/34497#34499 · In reply to: #34498

Gregory Beaver wrote:
> Gregory Beaver wrote:
> > […]
> 
> Hi again,
> 
> After a bit more thought, I revised things.  The attached patch is
> better - it simply copies the external file and saves it as the
> $test_file.  I also failed to mention that this is against PHP_5_3, but
> obviously could be ported to HEAD pretty much unmodified

OK, so it gets even better.  --EXPECTHEADERS-- is broken in
run-tests.php as well, it uses CLI sapi.  A quick scan of all .phpt
tests showed only 1 test actually using --EXPECTHEADERS--.

The patch is updated to shunt to cgi sapi if the test contains
EXPECTHEADERS because (duh) cli won't output any headers, causing tests
using it to fail.

Greg

---

## #34501 — Marcus Boerger — 2008-01-05T10:49:32+00:00

URL: https://externals.io/message/34497#34501 · In reply to: #34499

Hello Gregory,

Saturday, January 5, 2008, 4:25:00 AM, you wrote:

> Index: run-tests.php
> ===================================================================
> RCS file: /repository/php-src/run-tests.php,v
> retrieving revision 1.226.2.37.2.35.2.10
> diff -u -r1.226.2.37.2.35.2.10 run-tests.php
> --- run-tests.php       1 Jan 2008 06:15:40 -0000       1.226.2.37.2.35.2.10
> +++ run-tests.php       5 Jan 2008 03:22:01 -0000
> @@ -1034,7 +1034,7 @@
>                 if (preg_match('/^--([_A-Z]+)--/', $line, $r)) {
>                         $section = $r[1];
>                         $section_text[$section] = '';
> -                       $secfile = $section == 'FILE' || $section == 'FILEEOF';
> +                       $secfile = $section == 'FILE' || $section == 'FILEEOF' || $section
> == 'FILE_EXTERNAL';
>                         $secdone = false;
>                         continue;
>                 }
> @@ -1060,7 +1060,7 @@
>                         $borked = false;
>                 }
>         } else {
> -               if (@count($section_text['FILE']) +
> @count($section_text['FILEEOF']) != 1) {
> +               if (@count($section_text['FILE']) + @count($section_text['FILEEOF']) +
> @count($section_text['FILE_EXTERNAL']) != 1) {
>                         $bork_info = "missing section --FILE--";
>                         $borked = true;
>                 }
> @@ -1068,6 +1068,17 @@
>                         $section_text['FILE'] = preg_replace("/[\r\n]+$/", '',
> $section_text['FILEEOF']);
>                         unset($section_text['FILEEOF']);
>                 }
> +               if (@count($section_text['FILE_EXTERNAL']) == 1) {
> +                       // don't allow tests to retrieve files from anywhere but this
> subdirectory
> +                       $section_text['FILE_EXTERNAL'] = dirname($file) . '/' .
> trim(str_replace('..', '', $section_text['FILE_EXTERNAL']));
> +                       if (@file_exists($section_text['FILE_EXTERNAL'])) {
> +                               $section_text['FILE'] =
> file_get_contents($section_text['FILE_EXTERNAL']);
> +                               unset($section_text['FILE_EXTERNAL']);
> +                       } else {
> +                               $bork_info = "could not load --FILE_EXTERNAL-- " .
> dirname($file) . '/' . trim($section_text['FILE_EXTERNAL']);
> +                               $borked = true;
> +                       }
> +               }
>                 if ((@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) +
> @count($section_text['EXPECTREGEX'])) != 1) {
>                         $bork_info = "missing section --EXPECT--, --EXPECTF-- or
> --EXPECTREGEX--";
>                         $borked = true;
> @@ -1093,7 +1104,7 @@
>         $tested = trim($section_text['TEST']);
>  
>         /* For GET/POST tests, check if cgi sapi is available and if it is, use it. */
> -       if (!empty($section_text['GET']) || !empty($section_text['POST']) ||
> !empty($section_text['POST_RAW']) || !empty($section_text['COOKIE'])) {
> +       if (!empty($section_text['GET']) || !empty($section_text['POST']) ||
> !empty($section_text['POST_RAW']) || !empty($section_text['COOKIE']) ||
> !empty($section_text['EXPECT_HEADERS'])) {
>                 if (isset($php_cgi)) {
>                         $old_php = $php;
>                         $php = $php_cgi .' -C ';
> @@ -1355,12 +1366,15 @@
>                 $raw_lines = explode("\n", $post);
>  
>                 $request = '';
> +               $started = false;
>                 foreach ($raw_lines as $line) {
>                         if (empty($env['CONTENT_TYPE']) &&
> preg_match('/^Content-Type:(.*)/i', $line, $res)) {
>                                 $env['CONTENT_TYPE'] =
> trim(str_replace("\r", '', $res[1]));
>                                 continue;
>                         }
> -                       $request .= $line . "\n";
> +                       if ($started) $request .= "\n";
> +                       $started = true;
> +                       $request .= $line;
>                 }
>  
>                 $env['CONTENT_LENGTH'] = strlen($request);


Please apply this to PHP 5.2, 5.3 and HEAD.

Best regards,
 Marcus
