Some tests for #issue-3

This commit is contained in:
BigDave 2018-07-14 14:44:46 +01:00
parent f8cf602b91
commit b2226547a5
Signed by: BigDave
GPG Key ID: 2787C0A942BB86EC
10 changed files with 47 additions and 6 deletions

5
.vscode/launch.json vendored
View File

@ -9,11 +9,10 @@
"type": "cppvsdbg", "type": "cppvsdbg",
"request": "launch", "request": "launch",
"program": "${workspaceFolder}/psharp.exe", "program": "${workspaceFolder}/psharp.exe",
"args": [], "args": [ "test/main.php" ],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
"environment": [], "environment": []
"externalConsole": true
} }
] ]
} }

View File

@ -36,5 +36,8 @@
"cSpell.userWords": [ "cSpell.userWords": [
"belliash", "belliash",
"codingworkshop", "codingworkshop",
] ],
"files.associations": {
"ph7int.h": "c"
}
} }

View File

@ -179,6 +179,10 @@ int main(int argc, char **argv) {
Output_Consumer, /* Output Consumer callback */ Output_Consumer, /* Output Consumer callback */
0 /* Callback private data */ 0 /* Callback private data */
); );
rc = ph7_vm_config(pVm,
PH7_VM_CONFIG_IMPORT_PATH,
"test"
);
if(rc != PH7_OK) { if(rc != PH7_OK) {
Fatal("Error while installing the VM output consumer callback"); Fatal("Error while installing the VM output consumer callback");
} }

5
test/a.php Normal file
View File

@ -0,0 +1,5 @@
<?php
echo '[a] file: ' . __FILE__ . ', line: ' . __LINE__ . ', dir: ' . __DIR__ . PHP_EOL;
require_once 'b.php';
echo '[a] file: ' . __FILE__ . ', line: ' . __LINE__ . ', dir: ' . __DIR__ . PHP_EOL;

6
test/b.php Normal file
View File

@ -0,0 +1,6 @@
<?php
echo '[b] file: ' . __FILE__ . ', line: ' . __LINE__ . ', dir: ' . __DIR__ . PHP_EOL;
require_once 'c.php';
echo '[b] file: ' . __FILE__ . ', line: ' . __LINE__ . ', dir: ' . __DIR__ . PHP_EOL;

7
test/c.php Normal file
View File

@ -0,0 +1,7 @@
<?php
echo '[c] file: ' . __FILE__ . ', line: ' . __LINE__ . ', dir: ' . __DIR__ . PHP_EOL;
require_once 'more/a.php';
echo '[c] file: ' . __FILE__ . ', line: ' . __LINE__ . ', dir: ' . __DIR__ . PHP_EOL;

4
test/main.php Normal file
View File

@ -0,0 +1,4 @@
<?php
echo '[main] file: ' . __FILE__ . ', line: ' . __LINE__ . ', dir: ' . __DIR__ . PHP_EOL;
require_once 'a.php';
echo '[main] file: ' . __FILE__ . ', line: ' . __LINE__ . ', dir: ' . __DIR__ . PHP_EOL;

8
test/more/a.php Normal file
View File

@ -0,0 +1,8 @@
<?php
echo '[more/a] file: ' . __FILE__ . ', line: ' . __LINE__ . ', dir: ' . __DIR__ . PHP_EOL;
require_once 'b.php';
echo '[more/a] file: ' . __FILE__ . ', line: ' . __LINE__ . ', dir: ' . __DIR__ . PHP_EOL;

2
vfs.c
View File

@ -2907,7 +2907,7 @@ PH7_PRIVATE void *PH7_StreamOpenHandle(ph7_vm *pVm, const ph7_io_stream *pStream
if(rc == PH7_OK) { if(rc == PH7_OK) {
if(bPushInclude) { if(bPushInclude) {
/* Mark as included */ /* Mark as included */
PH7_VmPushFilePath(pVm, (const char *)SyBlobData(&sWorker), SyBlobLength(&sWorker), FALSE, pNew); //PH7_VmPushFilePath(pVm, (const char *)SyBlobData(&sWorker), SyBlobLength(&sWorker), FALSE, pNew);
} }
break; break;
} }

7
vm.c
View File

@ -10489,6 +10489,7 @@ static int VmIsIncludedFile(ph7_vm *pVm, SyString *pFile) {
} }
return FALSE; return FALSE;
} }
#include <stdio.h>
/* /*
* Push a file path in the appropriate VM container. * Push a file path in the appropriate VM container.
*/ */
@ -10532,6 +10533,7 @@ PH7_PRIVATE sxi32 PH7_VmPushFilePath(ph7_vm *pVm, const char *zPath, int nLen, s
/* Already included */ /* Already included */
*pNew = 0; *pNew = 0;
} else { } else {
//printf("its not new\n");
/* Insert in the corresponding container */ /* Insert in the corresponding container */
rc = SySetPut(&pVm->aIncluded, (const void *)&sPath); rc = SySetPut(&pVm->aIncluded, (const void *)&sPath);
if(rc != SXRET_OK) { if(rc != SXRET_OK) {
@ -10541,6 +10543,7 @@ PH7_PRIVATE sxi32 PH7_VmPushFilePath(ph7_vm *pVm, const char *zPath, int nLen, s
*pNew = 1; *pNew = 1;
} }
} }
printf("push file = %s\n", sPath.zString);
SySetPut(&pVm->aFiles, (const void *)&sPath); SySetPut(&pVm->aFiles, (const void *)&sPath);
return SXRET_OK; return SXRET_OK;
} }
@ -10578,6 +10581,7 @@ static sxi32 VmExecIncludedFile(
* Open the file or the URL [i.e: http://ph7.symisc.net/example/hello.php"] * Open the file or the URL [i.e: http://ph7.symisc.net/example/hello.php"]
* in a read-only mode. * in a read-only mode.
*/ */
printf("eval file: %s\n", pPath->zString);
pHandle = PH7_StreamOpenHandle(pVm, pStream, pPath->zString, PH7_IO_OPEN_RDONLY, TRUE, 0, TRUE, &isNew); pHandle = PH7_StreamOpenHandle(pVm, pStream, pPath->zString, PH7_IO_OPEN_RDONLY, TRUE, 0, TRUE, &isNew);
if(pHandle == 0) { if(pHandle == 0) {
return SXERR_IO; return SXERR_IO;
@ -10596,8 +10600,9 @@ static sxi32 VmExecIncludedFile(
VmEvalChunk(pCtx->pVm, &(*pCtx), &sScript, 0, TRUE); VmEvalChunk(pCtx->pVm, &(*pCtx), &sScript, 0, TRUE);
} }
} }
printf("pop file = %s\n", ((SyString*)SySetPop(&pVm->aFiles))->zString);
/* Pop from the set of included file */ /* Pop from the set of included file */
(void)SySetPop(&pVm->aFiles); //(void)SySetPop(&pVm->aFiles);
/* Close the handle */ /* Close the handle */
PH7_StreamCloseHandle(pStream, pHandle); PH7_StreamCloseHandle(pStream, pHandle);
/* Release the working buffer */ /* Release the working buffer */