php: Fix tests.

- Use ./run script to run the tests.
- Set environment variables correctly, including $PATH.
- Test the locally built, not installed, copy of libguestfs.
This commit is contained in:
Richard W.M. Jones
2013-03-11 16:04:17 +00:00
parent becc4fecf4
commit cd40cf7139
6 changed files with 60 additions and 14 deletions

View File

@@ -51,6 +51,9 @@ extension/config.h: extension/config.m4 ../config.status
cd extension && ./configure --prefix=$(prefix) --libdir=$(libdir)
test -f "$@" && touch -- $@
# Don't use --test because PHP always returns a success code.
TESTS_ENVIRONMENT = $(top_builddir)/run
TESTS = run-php-tests.sh
# Before PHP 5.4.0, the extension directory didn't have a 'make clean'

View File

@@ -5,6 +5,16 @@ Load the module and create a handle.
// See comment in php/run-php-tests.sh.
//putenv ('LIBGUESTFS_DEBUG=1');
if (! $fp = fopen ("env", "r")) {
die ("Error: cannot open environment file 'env'\n");
}
while (($buffer = fgets ($fp)) != false) {
putenv (chop ($buffer, "\n"));
}
if (!feof ($fp)) {
die ("Error: unexpected failure of fgets\n");
}
fclose ($fp);
$g = guestfs_create ();
if ($g == false) {

View File

@@ -5,6 +5,16 @@ Launch the appliance and run basic tests.
// See comment in php/run-php-tests.sh.
//putenv ('LIBGUESTFS_DEBUG=1');
if (! $fp = fopen ("env", "r")) {
die ("Error: cannot open environment file 'env'\n");
}
while (($buffer = fgets ($fp)) != false) {
putenv (chop ($buffer, "\n"));
}
if (!feof ($fp)) {
die ("Error: unexpected failure of fgets\n");
}
fclose ($fp);
$g = guestfs_create ();
if ($g == false) {

View File

@@ -5,6 +5,16 @@ Check function with optional arguments.
// See comment in php/run-php-tests.sh.
//putenv ('LIBGUESTFS_DEBUG=1');
if (! $fp = fopen ("env", "r")) {
die ("Error: cannot open environment file 'env'\n");
}
while (($buffer = fgets ($fp)) != false) {
putenv (chop ($buffer, "\n"));
}
if (!feof ($fp)) {
die ("Error: unexpected failure of fgets\n");
}
fclose ($fp);
$g = guestfs_create ();
if ($g == false) {

View File

@@ -1,5 +1,5 @@
#!/bin/sh -
# Copyright (C) 2010 Red Hat Inc.
#!/bin/bash -
# Copyright (C) 2010-2013 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -18,21 +18,33 @@
set -e
cd extension
# The PHP test script cleans the environment. (This is, apparently,
# to fully simulate how PHP runs when it runs in the context of
# Apache, and not only because PHP is written by morons). We
# therefore have to load the environment (from php/extension/env which
# is generated below) at the start of each test script.
# As a consequence of above, LIBGUESTFS_DEBUG=1 and LIBGUESTFS_TRACE=1
# won't get passed down to the script. Furthermore, setting debug or
# trace isn't very useful anyway because the PHP test script mixes
# stdout and stderr together and compares this to the expected output,
# so you'd just get failures for every test. So there is no good way
# to debug libguestfs failures in PHP tests, but if an individual test
# fails locally then you can edit the guestfs_php_*.phpt.in and
# uncomment the putenv statement, then look at the output.
unset LIBGUESTFS_DEBUG
unset LIBGUESTFS_TRACE
# This makes a file containing the environment variables we want to set.
rm -f env
echo "PATH=$PATH" > env
printenv | grep -E '^(LIBGUESTFS_|LIBVIRT_|LD_|MALLOC_)' >> env
TESTS=$(echo guestfs_php_*.phpt)
echo TESTS: $TESTS
# The PHP test script cleans the environment, so LIBGUESTFS_DEBUG=1
# won't get passed down to the script. Furthermore, setting
# LIBGUESTFS_DEBUG=1 isn't very useful anyway because the PHP test
# script mixes stdout and stderr together and compares this to the
# expected output, so you'd just get failures for every test. So
# there is no good way to debug libguestfs failures in PHP tests, but
# if an individual test fails locally then you can edit the
# guestfs_php_*.phpt and uncomment the putenv statement, then look at
# the output.
unset LIBGUESTFS_DEBUG
# By the way, we're actually testing the installed version of
# libguestfs. But don't worry, because PHP ignores the result of the
# tests anyway! ** Gah, PHP is written by morons ... **
# tests anyway!
make test TESTS="$TESTS"