From d0d062b4a05a9eb64b8d2e6d038af96ac532e4b3 Mon Sep 17 00:00:00 2001 From: valmat Date: Thu, 27 Mar 2014 01:19:12 +0600 Subject: Added new tests. Due to support zts broke the ability to run tests without installation - fixed. --- tests/cpp/Makefile | 2 +- tests/cpp/include/ValueIterator.h | 27 ++ tests/cpp/include/testValueIterator.h | 27 -- tests/cpp/include/variables.h | 293 +++++++++++++++++++++ tests/cpp/main.cpp | 31 ++- tests/cpp/zts/.gitignore | 1 + tests/php/dbg.php | 45 ---- tests/php/phpt/valueiterator/006.phpt | 21 -- tests/php/phpt/valueiterator/006.phpt- | 21 ++ tests/php/phpt/variables/001-process_globals.phpt- | 47 ++++ .../php/phpt/variables/002-get_complex_array.phpt- | 33 +++ tests/php/phpt/variables/003-value-types.phpt- | 72 +++++ .../phpt/variables/004-store-scalar-variables.phpt | 58 ++++ .../variables/005-value-casting-operators.phpt- | 174 ++++++++++++ tests/php/phpt/variables/006-casting-obj2str.phpt | 31 +++ .../phpt/variables/007-overloaded-operators.phpt | 51 ++++ tests/php/phpt/variables/008-value-arrays.phpt- | 89 +++++++ tests/php/phpt/variables/009-value-object.phpt- | 24 ++ tests/php/phpt/variables/010-value-object2.phpt | 24 ++ tests/php/phpt/variables/readme | 1 + tests/prepare.sh | 22 +- tests/readme | 6 +- tests/test.sh | 29 +- 23 files changed, 1021 insertions(+), 108 deletions(-) create mode 100644 tests/cpp/include/ValueIterator.h delete mode 100644 tests/cpp/include/testValueIterator.h create mode 100644 tests/cpp/include/variables.h create mode 100644 tests/cpp/zts/.gitignore delete mode 100644 tests/php/phpt/valueiterator/006.phpt create mode 100644 tests/php/phpt/valueiterator/006.phpt- create mode 100644 tests/php/phpt/variables/001-process_globals.phpt- create mode 100644 tests/php/phpt/variables/002-get_complex_array.phpt- create mode 100644 tests/php/phpt/variables/003-value-types.phpt- create mode 100644 tests/php/phpt/variables/004-store-scalar-variables.phpt create mode 100644 tests/php/phpt/variables/005-value-casting-operators.phpt- create mode 100644 tests/php/phpt/variables/006-casting-obj2str.phpt create mode 100644 tests/php/phpt/variables/007-overloaded-operators.phpt create mode 100644 tests/php/phpt/variables/008-value-arrays.phpt- create mode 100644 tests/php/phpt/variables/009-value-object.phpt- create mode 100644 tests/php/phpt/variables/010-value-object2.phpt create mode 100644 tests/php/phpt/variables/readme (limited to 'tests') diff --git a/tests/cpp/Makefile b/tests/cpp/Makefile index e0c32ba..6239170 100644 --- a/tests/cpp/Makefile +++ b/tests/cpp/Makefile @@ -88,7 +88,7 @@ LINKER = g++ # LIB_DIR=$(shell cd ../.. && pwd) -COMPILER_FLAGS = -Wall -c -O2 -std=c++11 -fpic -I"${LIB_DIR}/include" -o +COMPILER_FLAGS = -Wall -c -O2 -std=c++11 -fpic -I"${LIB_DIR}/include" -I"./zts" -o LINKER_FLAGS = -shared -L"${LIB_DIR}" LINKER_DEPENDENCIES = -lphpcpp diff --git a/tests/cpp/include/ValueIterator.h b/tests/cpp/include/ValueIterator.h new file mode 100644 index 0000000..a9329c9 --- /dev/null +++ b/tests/cpp/include/ValueIterator.h @@ -0,0 +1,27 @@ +/** + * + * TestValueIterator + * + */ + +/** + * Set up namespace + */ +namespace TestValueIterator { + + + void loopValue(Php::Parameters ¶ms) + { + std::cout << "Array/Object contains " << params[0].size() << " items" << std::endl; + for (auto it=params[0].begin(), itend = params[0].end(); it != itend; ++it) { + std::cout << "["<< it->first << "]="<< it->second << std::endl; + //std::cout << "["<< it->key() << "]="<< it->value() << std::endl; + } + return; + } + +/** + * End of namespace + */ +} + diff --git a/tests/cpp/include/testValueIterator.h b/tests/cpp/include/testValueIterator.h deleted file mode 100644 index a9329c9..0000000 --- a/tests/cpp/include/testValueIterator.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * - * TestValueIterator - * - */ - -/** - * Set up namespace - */ -namespace TestValueIterator { - - - void loopValue(Php::Parameters ¶ms) - { - std::cout << "Array/Object contains " << params[0].size() << " items" << std::endl; - for (auto it=params[0].begin(), itend = params[0].end(); it != itend; ++it) { - std::cout << "["<< it->first << "]="<< it->second << std::endl; - //std::cout << "["<< it->key() << "]="<< it->value() << std::endl; - } - return; - } - -/** - * End of namespace - */ -} - diff --git a/tests/cpp/include/variables.h b/tests/cpp/include/variables.h new file mode 100644 index 0000000..f242653 --- /dev/null +++ b/tests/cpp/include/variables.h @@ -0,0 +1,293 @@ +/** + * + * Test variables + * + */ + +/** + * Set up namespace + */ +namespace TestVariables { + + + /** + * process_globals() + * + * This function reads and modifies global variables + */ + Php::Value process_globals() + { + // all global variables can be accessed via the Php::GLOBALS variable, + // which is more or less the same as the PHP $_GLOBALS variable + + // set a global variable + Php::GLOBALS["a"] = 1; + + // increment a global variable + Php::GLOBALS["b"] += 1; + + // set a global variable to be an array + Php::GLOBALS["c"] = Php::Array(); + + // add a member to an array + Php::GLOBALS["c"]["member"] = 123; + + // and increment it + Php::GLOBALS["c"]["member"] += 77; + + // change value e + Php::GLOBALS["e"] = Php::GLOBALS["e"][0]("hello"); + + // if a global variable holds a function, we can call it + return Php::GLOBALS["d"](1,2,3); + } + + /** + * This function returns complex array + */ + Php::Value get_complex_array() + { + Php::Value r; + r["a"] = 123; + r["b"] = 456; + r["c"][0] = "nested value"; + r["c"][1] = "example"; + r["c"][2] = 7; + return r; + } + + + std::string bool2str(bool b) + { + return b ? "Yes" : "No"; + } + + /* + * Check type of value + * @param array + */ + void value_types(Php::Parameters ¶ms) { + if (params.size() == 0) { + return; + } + + Php::Value arr = params[0]; + + Php::out << "Null: " << bool2str( arr.get("Null").type() == Php::Type::Null ) << std::endl; + Php::out << "Numeric: " << bool2str( arr.get("Numeric").type() == Php::Type::Numeric ) << std::endl; + Php::out << "Float: " << bool2str( arr.get("Float").type() == Php::Type::Float ) << std::endl; + Php::out << "Bool: " << bool2str( arr.get("Bool").type() == Php::Type::Bool ) << std::endl; + Php::out << "Array: " << bool2str( arr.get("Array").type() == Php::Type::Array ) << std::endl; + Php::out << "Object: " << bool2str( arr.get("Object").type() == Php::Type::Object ) << std::endl; + Php::out << "String: " << bool2str( arr.get("String").type() == Php::Type::String ) << std::endl; + Php::out << "Resource: " << bool2str( arr.get("Resource").type() == Php::Type::Resource ) << std::endl; + Php::out << "Constant: " << bool2str( arr.get("Constant").type() == Php::Type::Constant ) << std::endl; + Php::out << "ConstantArray: " << bool2str( arr.get("ConstantArray").type() == Php::Type::ConstantArray ) << std::endl; + Php::out << "Callable1: " << bool2str( arr.get("Callable1").type() == Php::Type::Callable ) << std::endl; + Php::out << "Callable2: " << bool2str( arr.get("Callable2").type() == Php::Type::Callable ) << std::endl; + Php::out << "Callable3: " << bool2str( arr.get("Callable3").type() == Php::Type::Callable ) << std::endl; + Php::out << "Callable4: " << bool2str( arr.get("Callable4").type() == Php::Type::Callable ) << std::endl; + } + + /* + * Test variables defined in PHP-CPP + */ + Php::Value scalar_store(void) { + + Php::Value value1 = 1234; + Php::Value value2 = "this is a string"; + Php::Value value3 = std::string("another string"); + Php::Value value4 = nullptr; + Php::Value value5 = 123.45; + Php::Value value6 = true; + + Php::Value r; + r[0] = value1; + r[1] = value2; + r[2] = value3; + r[3] = value4; + r[4] = value5; + r[5] = value6; + + r[6] = 1234; + r[7] = "this is a string"; + r[8] = std::string("another string"); + r[9] = nullptr; + r[10] = Php::Value(); + r[11] = 123.45; + r[12] = false; + + return r; + } + + /* + * Test Php::Value casting operators + */ + void value_casting(Php::Parameters ¶ms) + { + Php::Value value = params[0]; + + long value1 = value; + std::string value2 = value; + //long double value3 = value; // <------------ error: conversion from ‘Php::Value’ to ‘long double’ is ambiguous + double value3 = value; + bool value4 = value; + + Php::out << " long:" << value1 << "\n string:" << value2 << "\n double:" << value3 << "\n bool:" << bool2str(value4) << std::endl; + } + + /* + * Test Php::Value casting operators + */ + void value_cast2str(Php::Parameters ¶ms) + { + std::string value = params[0]; + Php::out << value << std::endl; + } + + /* + * Test Php::Value overloaded operators + */ + void overloaded_op(Php::Parameters ¶ms) + { + Php::Value value = params[0]; + if (value == "some string") + { + Php::out << "value == 'some string'" << std::endl; + } + + if (value == 12) + { + Php::out << "value == 12" << std::endl; + } + else if (value > 100) + { + Php::out << "value > 100" << std::endl; + } + + value += 10; + Php::out << value << std::endl; + + int r1 = value - 8; + Php::out << r1 << std::endl; + + double r2 = value*123.45; + Php::out << r2 << std::endl; + + double r3 = value/123.45; + Php::out << r3 << std::endl; + + + + } + + /* + * Test Php::Value arrays + */ + Php::Value value_arrays(void) + { + // create a regular array + Php::Value array; + array[0] = "apple"; + array[1] = "banana"; + array[2] = "tomato"; + + // an initializer list can be used to create a filled array + Php::Value filled({ "a", "b", "c", "d"}); + + // create an associative array + Php::Value assoc; + assoc["apple"] = "green"; + assoc["banana"] = "yellow"; + assoc["tomato"] = "green"; + + // the variables in an array do not all have to be of the same type + Php::Value assoc2; + assoc2["x"] = "info@example.com"; + assoc2["y"] = nullptr; + assoc2["z"] = 123; + + // nested arrays are possible too + Php::Value assoc3; + assoc3["x"] = "info@example.com"; + assoc3["y"] = nullptr; + assoc3["z"][0] = "a"; + assoc3["z"][1] = "b"; + assoc3["z"][2] = "c"; + + Php::Value r; + r["array"] = array; + r["filled"] = filled; + r["assoc"] = assoc; + r["assoc2"] = assoc2; + r["assoc3"] = assoc3; + return r; + } + + /* + * Test Php::Value object + */ + Php::Value value_object1(void) + { + + // create empty object of type stdClass + Php::Object object; + + // object properties can be accessed with square brackets + object["property1"] = "value1"; + object["property2"] = "value2"; + + // Php::Value is the base class, so you can assign Php::Object objects + //Php::Value value = object; + + return object; + } + + /* + * Test Php::Value object + */ + Php::Value value_object2(void) + { + + // create empty object of type stdClass + Php::Object object; + + // to create an object of a different type, pass in the class name + // to the constructor with optional constructor parameters + //object = Php::Object("DateTime", "2014-03-27 00:37:15.638276"); + + auto timeZone = Php::Object("DateTimeZone", "Europe/Amsterdam"); + object = Php::Object("DateTime", "2014-03-27 00:37:15", timeZone); + + + // methods can be called with the call() method + Php::out << object.call("format", "Y-m-d H:i:s") << std::endl; + + // all these methods can be called on a Php::Value object too + Php::Value value = Php::Object("DateTime", "2016-03-31 15:48:00", timeZone); + Php::out << value.call("format", "Y-m-d H:i:s") << std::endl; + Php::out << value.call("getOffset") << std::endl; + + return object; + } + + /* + * Test Php::Value resize + */ + void ghfghfhf2(Php::Parameters ¶ms) + { + + + } + + + + + + + +/** + * End of namespace + */ +} + diff --git a/tests/cpp/main.cpp b/tests/cpp/main.cpp index 154b61b..2928f60 100644 --- a/tests/cpp/main.cpp +++ b/tests/cpp/main.cpp @@ -8,8 +8,10 @@ #include // Test includes -#include "include/testValueIterator.h" +#include "include/ValueIterator.h" #include "include/MyCustomClass.h" +#include "include/variables.h" + @@ -43,10 +45,35 @@ extern "C" // add the class to the extension extension.add(customClass); - + /** + * tests for Iterators + * + */ // add function to extension //extension.add("TestValueIterator\\loopValue", TestValueIterator::loopValue/*, { extension.add("TestValueIterator\\loopValue", TestValueIterator::loopValue); + + + /** + * tests for variables + * + */ + extension.add("TestVariables\\process_globals", TestVariables::process_globals); + extension.add("TestVariables\\get_complex_array", TestVariables::get_complex_array); + extension.add("TestVariables\\value_types", TestVariables::value_types); + extension.add("TestVariables\\scalar_store", TestVariables::scalar_store); + extension.add("TestVariables\\value_casting", TestVariables::value_casting); + extension.add("TestVariables\\value_cast2str", TestVariables::value_cast2str); + extension.add("TestVariables\\overloaded_op", TestVariables::overloaded_op); + extension.add("TestVariables\\value_arrays", TestVariables::value_arrays); + extension.add("TestVariables\\value_object1", TestVariables::value_object1); + extension.add("TestVariables\\value_object2", TestVariables::value_object2); + + + + + + // return the extension module return extension; diff --git a/tests/cpp/zts/.gitignore b/tests/cpp/zts/.gitignore new file mode 100644 index 0000000..8d82a92 --- /dev/null +++ b/tests/cpp/zts/.gitignore @@ -0,0 +1 @@ +phpcpp/config.h diff --git a/tests/php/dbg.php b/tests/php/dbg.php index 6f1dabc..9a28fc6 100644 --- a/tests/php/dbg.php +++ b/tests/php/dbg.php @@ -6,51 +6,6 @@ */ -function out($obj) { - - - $cl_name = is_object($obj) ? - get_class($obj) : - (is_array($obj) ? "Array" : "----"); - - echo "++++-" , $cl_name , "-++++\n"; - - echo "\x1b[1;31m"; - echo "\n Native iterate:\n\n"; - foreach($obj as $k => $v) { - echo "$k\t=>\t$v\n"; - } - echo "\x1b[0m"; - - - TestValueIterator\loopValue($obj); -} - - - -require './include/valueiterator/1.php'; - -#$arr = array('qwe' => 'qweqweqweqw',5,'asd' => '«£¥§©®°±¶⅐⅒⅓⅘⅞Ⅻↆ❄❅❆⚑⚐⌛⌚〰»', 'zxccvx' => 'sdfsecvyh6bug6yfty',); -#$obj = (object)$arr; -#$smpl = new SimpleClass; -#$it = new impIterator; -#$iag1 = new impIterAggr1; -$iag2 = new impIterAggr2; - - -//out($arr); -#out($obj); -#out($smpl); -TestValueIterator\loopValue($iag2); -#out($it); -#out($iag1); -#out($iag2); - - - - - - diff --git a/tests/php/phpt/valueiterator/006.phpt b/tests/php/phpt/valueiterator/006.phpt deleted file mode 100644 index ea97c2b..0000000 --- a/tests/php/phpt/valueiterator/006.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Iterate itarable oblect ---DESCRIPTION-- -class impIterAggr1 implements IteratorAggregate ---SKIPIF-- - ---FILEEOF-- - +--FILEEOF-- + +--SKIPIF-- + +--FILEEOF-- + +--FILEEOF-- + 123, + "b" => 456, + "c" => array("nested_value","example",7) + ); +} +var_export(get_complex_array()); +*/ +var_export(TestVariables\get_complex_array()); + + +echo PHP_EOL; +--EXPECT-- +array ( + 'a' => 123, + 'b' => 456, + 'c' => + array ( + 0 => 'nested_value', + 1 => 'example', + 2 => 7, + ), +) \ No newline at end of file diff --git a/tests/php/phpt/variables/003-value-types.phpt- b/tests/php/phpt/variables/003-value-types.phpt- new file mode 100644 index 0000000..477fbe2 --- /dev/null +++ b/tests/php/phpt/variables/003-value-types.phpt- @@ -0,0 +1,72 @@ +--TEST-- +get_complex_array +--SKIPIF-- + +--FILEEOF-- + NULL, + 'Numeric' => 2014, + 'Float' => 3.14, + 'Bool' => true, + 'Array' => array(5,'a' => 33, 'str'), + 'Object' => new stdClass(), + 'String' => 'String', + 'Resource' => 7, + 'Constant' => 5, + 'ConstantArray' => 11, + 'Callable1' => 'ret5', + 'Callable2' => $methodVariable, + 'Callable3' => function () {return 5;}, + 'Callable4' => new CallableClass() +); + +TestVariables\value_types($arr); + +//To check uncomment the following lines: +/* +echo "\n\nCallable1:"; +var_export(is_callable($arr['Callable1'])); +echo PHP_EOL,'Callable2:'; +var_export(is_callable($arr['Callable2'])); +echo PHP_EOL,'Callable3:'; +var_export(is_callable($arr['Callable3'])); +echo PHP_EOL,'Callable4:'; +var_export(is_callable($arr['Callable4'])); +echo PHP_EOL,'No Callable:'; +var_export(is_callable(new stdClass)); +*/ + + +echo PHP_EOL; +--EXPECT-- +Null: Yes +Numeric: Yes +Float: Yes +Bool: Yes +Array: Yes +Object: Yes +String: Yes +Resource: No +Constant: No +ConstantArray: No +Callable1: Yes +Callable2: Yes +Callable3: Yes +Callable4: Yes \ No newline at end of file diff --git a/tests/php/phpt/variables/004-store-scalar-variables.phpt b/tests/php/phpt/variables/004-store-scalar-variables.phpt new file mode 100644 index 0000000..53cc681 --- /dev/null +++ b/tests/php/phpt/variables/004-store-scalar-variables.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test variables defined in PHP-CPP +--DESCRIPTION-- +in PHP-CPP: +Php::Value scalar_store(void) { + + Php::Value value1 = 1234; + Php::Value value2 = "this is a string"; + Php::Value value3 = std::string("another string"); + Php::Value value4 = nullptr; + Php::Value value5 = 123.45; + Php::Value value6 = true; + + Php::Value r; + r[0] = value1; + r[1] = value2; + r[2] = value3; + r[3] = value4; + r[4] = value5; + r[5] = value6; + + r[6] = 1234; + r[7] = "this is a string"; + r[8] = std::string("another string"); + r[9] = nullptr; // NULL + r[10] = Php::Value(); // NULL + r[11] = 123.45; + r[12] = false; + + return r; +} + +--SKIPIF-- + +--FILEEOF-- + 1234, + 1 => 'this is a string', + 2 => 'another string', + 3 => NULL, + 4 => 123.45, + 5 => true, + 6 => 1234, + 7 => 'this is a string', + 8 => 'another string', + 9 => NULL, + 10 => NULL, + 11 => 123.45, + 12 => false, +) diff --git a/tests/php/phpt/variables/005-value-casting-operators.phpt- b/tests/php/phpt/variables/005-value-casting-operators.phpt- new file mode 100644 index 0000000..5e0fb8e --- /dev/null +++ b/tests/php/phpt/variables/005-value-casting-operators.phpt- @@ -0,0 +1,174 @@ +--TEST-- +Test Php::Value casting operators +--DESCRIPTION-- +The Php::Value class has casting operators to cast the object to almost every thinkable native type. + + +It seems need to replace double on long double + +native_value_casting - repeats the behavior of c++ functions TestVariables\value_casting +the output of each of these functions should be the same + + +--SKIPIF-- + +--FILEEOF-- + +--FILEEOF-- + +--FILEEOF-- + 100 +130 +122 +16048.5 +1.05306 +-990 +-998 +-122216 +-8.01944 +value == 'some string' +10 +2 +1234.5 +0.0810045 \ No newline at end of file diff --git a/tests/php/phpt/variables/008-value-arrays.phpt- b/tests/php/phpt/variables/008-value-arrays.phpt- new file mode 100644 index 0000000..6950780 --- /dev/null +++ b/tests/php/phpt/variables/008-value-arrays.phpt- @@ -0,0 +1,89 @@ +--TEST-- +Test Php::Value arrays +--DESCRIPTION-- +--SKIPIF-- + +--FILEEOF-- + + array ( + 0 => 'apple', + 1 => 'banana', + 2 => 'tomato', + ), + 'filled' => + array ( + 0 => 'a', + 1 => 'b', + 2 => 'c', + 3 => 'd', + ), + 'assoc' => + array ( + 'apple' => 'green', + 'banana' => 'yellow', + 'tomato' => 'green', + ), + 'assoc2' => + array ( + 'x' => 'info@example.com', + 'y' => NULL, + 'z' => 123, + ), + 'assoc3' => + array ( + 'x' => 'info@example.com', + 'y' => NULL, + 'z' => + array ( + 0 => 'a', + 1 => 'b', + 2 => 'c', + ), + ), +) \ No newline at end of file diff --git a/tests/php/phpt/variables/009-value-object.phpt- b/tests/php/phpt/variables/009-value-object.phpt- new file mode 100644 index 0000000..c45cae8 --- /dev/null +++ b/tests/php/phpt/variables/009-value-object.phpt- @@ -0,0 +1,24 @@ +--TEST-- +Test Php::Value object #1 +--DESCRIPTION-- + create empty object of type stdClass + object properties can be accessed with square brackets +--SKIPIF-- + +--FILEEOF-- + "value1", "property2" => "value2"); + +var_export($object); + + + +--EXPECT-- +stdClass::__set_state(array( + 'property1' => 'value1', + 'property2' => 'value2', +)) \ No newline at end of file diff --git a/tests/php/phpt/variables/010-value-object2.phpt b/tests/php/phpt/variables/010-value-object2.phpt new file mode 100644 index 0000000..8697a69 --- /dev/null +++ b/tests/php/phpt/variables/010-value-object2.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test Php::Value object #2 +--DESCRIPTION-- + create empty object of type stdClass + object properties can be accessed with square brackets +--SKIPIF-- + +--FILEEOF-- + '2014-03-27 00:37:15', + 'timezone_type' => 3, + 'timezone' => 'Europe/Amsterdam', +)) \ No newline at end of file diff --git a/tests/php/phpt/variables/readme b/tests/php/phpt/variables/readme new file mode 100644 index 0000000..8162526 --- /dev/null +++ b/tests/php/phpt/variables/readme @@ -0,0 +1 @@ +tests variables diff --git a/tests/prepare.sh b/tests/prepare.sh index 58fc646..6c0e331 100755 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -1,27 +1,31 @@ #!/bin/bash # -# do not run this script. -# Create a local copy of the directory with the extension for run without installation +# do not run this script manualy. +# This script is intended to be run from a script test.sh +# Create a local copy of the directory with the extension for run tests without installation +# +# @author valmat # - +# Local directory in which to copy the links to all installed extensions EXTDLOC=ext_dir +mkdir -p "./$EXTDLOC" + SO=extfortest.so +# to check whether specified the extension name as parameter if [ $1 ] then SO=$1 fi +# a directory of extensions already installed in the operating system EXTDIR=$(php-config --extension-dir) -#echo $EXTDIR - -mkdir -p "./$EXTDLOC" +# To copy references for all extensions to the local directory for LIBFILE in `find $EXTDIR -type f -or -type l -name "*.so"`; do BN=$(basename $LIBFILE) - PWD=$(pwd) NF="$PWD/$EXTDLOC/$BN" # if still no exist @@ -29,7 +33,6 @@ for LIBFILE in `find $EXTDIR -type f -or -type l -name "*.so"`; do then if [ -L $LIBFILE ]; then - #echo "cp $LIBFILE $NF" cp --no-dereference $LIBFILE $NF else ln -s $LIBFILE $NF @@ -40,10 +43,9 @@ for LIBFILE in `find $EXTDIR -type f -or -type l -name "*.so"`; do done # current extention -if [ ! -L "$PWD/$EXTDLOC/$SO" ]; +if [ ! -L "$PWD/$EXTDLOC/$SO" ] then ln -s "$PWD/cpp/$SO" "$PWD/$EXTDLOC/$SO" fi - diff --git a/tests/readme b/tests/readme index 1134f51..929f1b9 100644 --- a/tests/readme +++ b/tests/readme @@ -1,3 +1,7 @@ In this directory cpp extension is designed to conduct tests. When creating a test, do not use extension requiring the installation. -In the catalog php are the tests themselves. +In the directory php are the tests themselves. + +You can run test.sh with additional options. +The full list of available options see ./test.sh -h + diff --git a/tests/test.sh b/tests/test.sh index 952bf17..58f65ad 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -2,6 +2,8 @@ # # It is intended to run the command "make test" from the root directory of the library # +# @author valmat +# THIS=`basename $0` @@ -19,6 +21,7 @@ function print_help() { echo " -g Comma separated list of groups to show during test run" echo " (possible values: PASS, FAIL, XFAIL, SKIP, BORK, WARN, LEAK, REDIRECT)." echo " -m Test for memory leaks with Valgrind." + echo " -r Removes all auxiliary files. (*.log, *.diff etc)." echo " -s Write output to ." echo " -x Sets 'SKIP_SLOW_TESTS' environmental variable." echo " -o Cancels sets 'SKIP_ONLINE_TESTS' (default set)." @@ -30,12 +33,14 @@ function print_help() { } PHP_BIN="/usr/bin/php" +# options list SCR_OPT="" COMPILE_EXT=1 +# SKIP_ONLINE_TESTS == true OFFLINE=1 EXT_NAME="extfortest.so" -while getopts ":p:e:nw:a:d:g:ms:xoqvh" opt ; +while getopts ":p:e:nw:a:d:g:mrs:xoqvh" opt ; do case $opt in p) @@ -65,10 +70,29 @@ do m) SCR_OPT="$SCR_OPT -m" ;; + r) + # Removes all auxiliary files. (*.log, *.diff etc). + + # if quiet, only delete + if [ $(echo $SCR_OPT | grep -o "\-q") ]; then + find ./php/phpt -type f \( -name '*.diff' -or -name '*.exp' -or -name '*.log' -or -name '*.out' -or -name '*.php' -or -name '*.sh' -or -name '*.mem' \) -delete + + # else delete and print + else + echo -e "\x1b[1;31;47mRemove auxiliary files...\x1b[0;0m" + for AUXF in `find ./php/phpt -type f \( -name '*.diff' -or -name '*.exp' -or -name '*.log' -or -name '*.out' -or -name '*.php' -or -name '*.sh' -or -name '*.mem' \)`; + do + echo -e "\x1b[1;31;47mdel \x1b[0;30;47m$(dirname $AUXF)/\x1b[1;31;47m$(basename $AUXF)\x1b[0;30;47m ...\x1b[0;0m" + rm $AUXF + done + fi + exit; + ;; x) SCR_OPT="$SCR_OPT -x" ;; o) + # SKIP_ONLINE_TESTS == false OFFLINE=0 ;; q) @@ -92,7 +116,10 @@ done if [ 1 = $OFFLINE ]; then SCR_OPT="$SCR_OPT --offline" fi + +# A list of all additional options SCR_OPT="$SCR_OPT -d extension_dir=$PWD/ext_dir -d extension=$EXT_NAME" +# The file list of the tests that will be launched TEST_FILES=`find ./php/phpt -type f -name "*.phpt"` -- cgit v1.2.3