]> granicus.if.org Git - php/commitdiff
more tests
authorkrakjoe <joe.watkins@live.co.uk>
Fri, 6 Dec 2013 20:56:16 +0000 (20:56 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Fri, 6 Dec 2013 20:56:16 +0000 (20:56 +0000)
add phpdbg_exec userland function

Changelog.md
phpdbg.c
tests/commands/0104_clean.test [new file with mode: 0644]
tests/commands/0105_clear.test [new file with mode: 0644]
tests/commands/0106_compile.test [new file with mode: 0644]

index 308b68c4c8bb891dfa153e8a156eb25897635e1c..b49390f636e69ae698ed9aaca8c29b2bc1a0f558 100644 (file)
@@ -11,6 +11,8 @@ Version 0.3.0 2013-00-00
 5. Fix crash when loading .phpdbginit with command line switch
 6. Fix crash on startup errors
 7. Added init.d for remote console (redhat)
+8. Added phpdbg_exec userland function
+9. Added testing facilities
 
 Version 0.2.0 2013-11-31
 ------------------------
index 2a8726520cd78782bca2b203a0f1d89866c38533..1bd79bbd5f4b7d1091d8d5641f910c0520541ebc 100644 (file)
--- a/phpdbg.c
+++ b/phpdbg.c
@@ -199,6 +199,51 @@ static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */
        return SUCCESS;
 } /* }}} */
 
+/* {{{ proto mixed phpdbg_exec(string context) 
+       Attempt to set the execution context for phpdbg
+       If the execution context was set previously it is returned
+       If the execution context was not set previously boolean true is returned 
+       If the request to set the context fails, boolean false is returned, and an E_WARNING raised */
+static PHP_FUNCTION(phpdbg_exec) 
+{
+       char *exec = NULL;
+       zend_ulong exec_len = 0L;
+       
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &exec, &exec_len) == FAILURE) {
+               return;
+       }
+       
+       {
+               struct stat sb;
+               zend_bool result = 1;
+               
+               if (VCWD_STAT(exec, &sb) != FAILURE) {
+                       if (sb.st_mode & (S_IFREG|S_IFLNK)) {
+                               if (PHPDBG_G(exec)) {
+                                       ZVAL_STRINGL(return_value, PHPDBG_G(exec), PHPDBG_G(exec_len), 1);
+                                       efree(PHPDBG_G(exec));
+                                       result = 0;
+                               }
+                       
+                               PHPDBG_G(exec) = estrndup(exec, exec_len);
+                               PHPDBG_G(exec_len) = exec_len;
+                       
+                               if (result) 
+                                       ZVAL_BOOL(return_value, 1);
+                       } else {
+                               zend_error(
+                                       E_WARNING, "Failed to set execution context (%s), not a regular file or symlink", exec);
+                               ZVAL_BOOL(return_value, 0);
+                       }
+               } else {
+                       zend_error(
+                               E_WARNING, "Failed to set execution context (%s) the file does not exist", exec);
+
+                       ZVAL_BOOL(return_value, 0);
+               }
+       }
+} /* }}} */
+
 /* {{{ proto void phpdbg_break([integer type, string expression])
     instructs phpdbg to insert a breakpoint at the next opcode */
 static PHP_FUNCTION(phpdbg_break)
@@ -307,12 +352,17 @@ ZEND_BEGIN_ARG_INFO_EX(phpdbg_prompt_arginfo, 0, 0, 0)
        ZEND_ARG_INFO(0, string)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(phpdbg_exec_arginfo, 0, 0, 0)
+       ZEND_ARG_INFO(0, context)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO_EX(phpdbg_clear_arginfo, 0, 0, 0)
 ZEND_END_ARG_INFO()
 
 zend_function_entry phpdbg_user_functions[] = {
        PHP_FE(phpdbg_clear, phpdbg_clear_arginfo)
        PHP_FE(phpdbg_break, phpdbg_break_arginfo)
+       PHP_FE(phpdbg_exec,  phpdbg_exec_arginfo)
        PHP_FE(phpdbg_color, phpdbg_color_arginfo)
        PHP_FE(phpdbg_prompt, phpdbg_prompt_arginfo)
 #ifdef  PHP_FE_END
diff --git a/tests/commands/0104_clean.test b/tests/commands/0104_clean.test
new file mode 100644 (file)
index 0000000..c7a579b
--- /dev/null
@@ -0,0 +1,15 @@
+#################################################
+# name: clean
+# purpose: test cleaning environment
+# expect: TEST::FORMAT
+# options: -rr
+#################################################
+#[Cleaning Execution Environment]
+#Classes                       %d
+#Functions             %d
+#Constants             %d
+#Includes              %d
+#[Nothing to execute!]
+#################################################
+clean
+quit
diff --git a/tests/commands/0105_clear.test b/tests/commands/0105_clear.test
new file mode 100644 (file)
index 0000000..1ac3c3b
--- /dev/null
@@ -0,0 +1,15 @@
+#################################################
+# name: clear
+# purpose: test clearing breakpoints
+# expect: TEST::FORMAT
+# options: -rr
+#################################################
+#[Clearing Breakpoints]
+#File                  0
+#Functions             0
+#Methods                       0
+#Oplines                       0
+#Conditionals          0
+#################################################
+clear
+quit
diff --git a/tests/commands/0106_compile.test b/tests/commands/0106_compile.test
new file mode 100644 (file)
index 0000000..d79211d
--- /dev/null
@@ -0,0 +1,19 @@
+#################################################
+# name: compile
+# purpose: test compiling code
+# expect: TEST::FORMAT
+# options: -rr
+#################################################
+#[Attempting compilation of %s]
+#[Success]
+#Hello World
+#################################################
+<:
+define('OUT', 
+       tempnam(null, "phpdbg"));
+file_put_contents(OUT, "<?php echo \"Hello World\"; ?>");
+phpdbg_exec(OUT);
+:>
+compile
+run
+quit