public function testFromFile() { $testFiles = glob(__DIR__ . '/Functional/*.lisphp'); foreach ($testFiles as $file) { $code = file_get_contents($file); $scope = Lisphp_Environment::workflow(); $program = new Lisphp_Program($code); $result = $program->execute($scope); $expected = file_get_contents(preg_replace('/\\.lisphp$/', '.out', $file)); $this->assertSame(trim($expected), trim($result)); } }
function balrog_front_controller($baseDir) { $environment = Lisphp_Environment::full(); $scope = new Lisphp_Scope($environment); $scope['require'] = new Lisphp_Runtime_PHPFunction(function ($file) use($scope) { $program = Lisphp_Program::load(__DIR__ . '/' . $file . '.lisphp'); return $program->execute($scope); }); $scope['base-dir'] = $baseDir; $filename = __DIR__ . '/front-controller.lisphp'; $program = Lisphp_Program::load($filename); $program->execute($scope); }
public function testFromFile() { $testFiles = glob(__DIR__ . '/Functional/*.lisphp'); foreach ($testFiles as $file) { $this->result = ''; $program = Lisphp_Program::load($file); $scope = Lisphp_Environment::full(); $scope['echo'] = new Lisphp_Runtime_PHPFunction(array($this, 'displayStrings')); $program->execute($scope); $expected = file_get_contents(preg_replace('/\\.lisphp$/', '.out', $file)); $this->assertSame(trim($expected), trim($this->result)); } }
public function testFromFile() { $program = Lisphp_Program::load(__DIR__ . '/sample.lisphp'); $this->assertEquals(3, count($program)); try { Lisphp_Program::load($f = __DIR__ . '/sample2.lisphp'); $this->fail(); } catch (Lisphp_ParsingException $e) { $this->assertEquals(file_get_contents($f), $e->code); $this->assertEquals($f, $e->getLisphpFile()); $this->assertEquals(2, $e->getLisphpLine()); $this->assertEquals(32, $e->getLisphpColumn()); } }
<?php require dirname(__FILE__) . '/Lisphp.php'; $options = getopt('v', array('verbose')); function displayStrings() { global $result; $args = func_get_args(); $result .= join('', array_map('strval', $args)); } $testFiles = glob(dirname(__FILE__) . '/tests/*.lisphp'); $fails = array(); foreach ($testFiles as $file) { $program = Lisphp_Program::load($file); $result = ''; $scope = Lisphp_Environment::full(); $scope['echo'] = new Lisphp_Runtime_PHPFunction('displayStrings'); $program->execute($scope); $expected = file_get_contents(preg_replace('/\\.lisphp$/', '.out', $file)); if (trim($result) == trim($expected)) { echo '.'; } else { echo 'F'; $fails[$file] = $result; } } if ($fails) { echo "\nFailed: "; } else { echo "\nOK "; }
/** * @return \Phalcon\Http\ResponseInterface|string|void */ public function resultAction() { $hash_id = $this->request->getQuery('id', 'string', ''); $workflow = $this->workflow->findFirst($hash_id, $this->current_user->id); if ($workflow) { // delete old result $result = WorkflowResult::findByWf_id($workflow->id); $result->delete(); // set globals var $GLOBALS['workflow_id'] = $workflow->id; $GLOBALS['user_id'] = $this->current_user->id; $var_code = ''; $var = WorkflowVar::findByWf_id($workflow->id); foreach ($var as $item) { if (is_string($item->value)) { $var_code .= sprintf('(define %s "%s")', $item->name, str_replace('"', '\\"', $item->value)); } else { $var_code .= sprintf('(define %s %s)', $item->name, $item->value); } } // run code try { $env = Lisphp_Environment::workflow(); $program = new Lisphp_Program($var_code . $workflow->code_snippets); $code_result = $program->execute($env); } catch (Exception $e) { $code_result = $e->getMessage(); } // active UserActive::record('workflow-run', $this->current_user->id); // unset globals var unset($GLOBALS['workflow_id']); // new result $workflow_result = WorkflowResult::findByWf_id($workflow->id); $this->view->setVar('title', $workflow->title); $this->view->setVar('code_result', $code_result); $this->view->setVar('workflow_result', $workflow_result); return $this->view->partial('workflow/result'); } else { return $this->response->redirect('workflow/lists'); } }