Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34497 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20307 invoked by uid 1010); 5 Jan 2008 01:05:22 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 20291 invoked from network); 5 Jan 2008 01:05:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jan 2008 01:05:22 -0000 Authentication-Results: pb1.pair.com smtp.mail=greg@chiaraquartet.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=greg@chiaraquartet.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain chiaraquartet.net from 38.99.98.18 cause and error) X-PHP-List-Original-Sender: greg@chiaraquartet.net X-Host-Fingerprint: 38.99.98.18 beast.bluga.net Linux 2.6 Received: from [38.99.98.18] ([38.99.98.18:53843] helo=mail.bluga.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D7/17-14872-FC7DE774 for ; Fri, 04 Jan 2008 20:05:20 -0500 Received: from mail.bluga.net (localhost.localdomain [127.0.0.1]) by mail.bluga.net (Postfix) with ESMTP id 30452C0F1A4 for ; Fri, 4 Jan 2008 18:05:17 -0700 (MST) Received: from [192.168.0.106] (CPE-76-84-11-224.neb.res.rr.com [76.84.11.224]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.bluga.net (Postfix) with ESMTP id CC1E7C0F1A2 for ; Fri, 4 Jan 2008 18:05:16 -0700 (MST) Message-ID: <477ED7CC.4090307@chiaraquartet.net> Date: Fri, 04 Jan 2008 19:05:16 -0600 User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 To: internals Mailing List X-Enigmail-Version: 0.95.0 Content-Type: multipart/mixed; boundary="------------070201020709080601090909" X-Virus-Scanned: ClamAV using ClamSMTP Subject: how to test using run-tests? From: greg@chiaraquartet.net (Gregory Beaver) --------------070201020709080601090909 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 --------------070201020709080601090909 Content-Type: text/plain; name="extfile.patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="extfile.patch.txt" 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 00:59:38 -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,16 @@ $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'])) { + $bork_info = "could not load --FILE_EXTERNAL-- " . dirname($file) . '/' . trim($section_text['FILE_EXTERNAL']); + $borked = true; + } else { + $test_file = $section_text['FILE_EXTERNAL']; + } + } if ((@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX'])) != 1) { $bork_info = "missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX--"; $borked = true; @@ -1133,7 +1143,9 @@ $output_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'out'; $memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'mem'; $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'php'; - $test_file = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'php'; + if (!@count($section_text['FILE_EXTERNAL'])) { + $test_file = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'php'; + } $temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'skip.php'; $test_skipif = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'skip.php'; $temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'clean.php'; @@ -1177,7 +1189,9 @@ @unlink($output_filename); @unlink($memcheck_filename); @unlink($temp_file); - @unlink($test_file); + if (!@count($section_text['FILE_EXTERNAL'])) { + @unlink($test_file); + } @unlink($temp_skipif); @unlink($test_skipif); @unlink($tmp_post); @@ -1330,7 +1344,9 @@ // We've satisfied the preconditions - run the test! show_file_block('php', $section_text['FILE'], 'TEST'); - save_text($test_file, $section_text['FILE'], $temp_file); + if (!@count($section_text['FILE_EXTERNAL'])) { + save_text($test_file, $section_text['FILE'], $temp_file); + } if (array_key_exists('GET', $section_text)) { $query_string = trim($section_text['GET']); } else { @@ -1355,12 +1371,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); --------------070201020709080601090909--