Browse Source

checks that all snippets are executable

pull/63/merge
Martin Monperrus 9 years ago
parent
commit
f6e400371b
  1. 1
      .travis.yml
  2. 30
      bibtexbrowser-test.php
  3. 102
      bibtexbrowser.php

1
.travis.yml

@ -3,6 +3,7 @@ language: php
php: 5.4 php: 5.4
script: script:
- curl -o reflectivedoc.php http://www.monperrus.net/martin/reflectivedoc.php.txt
- curl -o gakowiki-syntax.php http://www.monperrus.net/martin/gakowiki-syntax.php.txt - curl -o gakowiki-syntax.php http://www.monperrus.net/martin/gakowiki-syntax.php.txt
- phpunit bibtexbrowser-test.php - phpunit bibtexbrowser-test.php

30
bibtexbrowser-test.php

@ -10,19 +10,41 @@ $ phpunit --coverage-html ./coverage btb-test.php
(be sure that xdebug is enabled: /etc/php5/cli/conf.d# ln -s ../../mods-available/xdebug.ini) (be sure that xdebug is enabled: /etc/php5/cli/conf.d# ln -s ../../mods-available/xdebug.ini)
*/ */
$_GET['library']=1;
function exception_error_handler($severity, $message, $file, $line) {
if ($severity != E_ERROR) {
//trigger_error($message);
return;
}
throw new ErrorException($message, 0, $severity, $file, $line);
}
error_reporting(E_ALL);
@copy('bibtexbrowser.local.php','bibtexbrowser.local.php.bak'); @copy('bibtexbrowser.local.php','bibtexbrowser.local.php.bak');
@unlink('bibtexbrowser.local.php'); @unlink('bibtexbrowser.local.php');
if(is_file('reflectivedoc.php')) {
set_error_handler("exception_error_handler");
require('reflectivedoc.php');
$_GET['library'] = 1;
foreach(getAllSnippetsInFile('bibtexbrowser.php') as $snippet) {
//echo $snippet;
ob_start();
eval($snippet);
ob_get_clean();
unset($_GET['bib']);
}
restore_error_handler();
} else {
$_GET['library']=1;
require_once ('bibtexbrowser.php'); require_once ('bibtexbrowser.php');
}
error_reporting(E_ALL);
class BTBTest extends PHPUnit_Framework_TestCase { class BTBTest extends PHPUnit_Framework_TestCase {
function test_checkdoc() { function test_checkdoc() {
include('gakowiki-syntax.php');
if(!is_file('gakowiki-syntax.php')) { return; }
if (!function_exists('gk_wiki2html')) { include('gakowiki-syntax.php'); }
create_wiki_parser()->parse(file_get_contents('bibtexbrowser-documentation.wiki')); create_wiki_parser()->parse(file_get_contents('bibtexbrowser-documentation.wiki'));
} }
@ -578,4 +600,6 @@ class BTBTest extends PHPUnit_Framework_TestCase {
} // end class } // end class
@copy('bibtexbrowser.local.php.bak','bibtexbrowser.local.php');
?> ?>

102
bibtexbrowser.php

@ -478,7 +478,7 @@ usage:
<pre> <pre>
$delegate = new XMLPrettyPrinter();// or another delegate such as BibDBBuilder $delegate = new XMLPrettyPrinter();// or another delegate such as BibDBBuilder
$parser = new StateBasedBibtexParser($delegate); $parser = new StateBasedBibtexParser($delegate);
$parser->parse('foo.bib');
$parser->parse(fopen('bibacid-utf8.bib','r'));
</pre> </pre>
notes: notes:
- It has no dependencies, it can be used outside of bibtexbrowser - It has no dependencies, it can be used outside of bibtexbrowser
@ -493,6 +493,7 @@ class StateBasedBibtexParser {
} }
function parse($handle) { function parse($handle) {
if (gettype($handle) == 'string') { throw new Exception('oops'); }
$delegate = &$this->delegate; $delegate = &$this->delegate;
// STATE DEFINITIONS // STATE DEFINITIONS
@define('NOTHING',1); @define('NOTHING',1);
@ -714,11 +715,36 @@ class StateBasedBibtexParser {
} // end function } // end function
} // end class } // end class
/** is a delegate for StateBasedBibParser.
/** a default empty implementation of a delegate for StateBasedBibtexParser */
class ParserDelegate {
function beginFile() {}
function endFile() {}
function setEntryField($finalkey,$entryvalue) {}
function setEntryType($entrytype) {}
function setEntryKey($entrykey) {}
function beginEntry() {}
function endEntry($entrysource) {}
/** called for each sub parts of type {part} of a field value
* for now, only CURLYTOP and CURLYONE events
*/
function entryValuePart($key, $value, $type) {}
} // end class ParserDelegate
/** is a possible delegate for StateBasedBibParser.
usage: usage:
see snippet of [[#StateBasedBibParser]] see snippet of [[#StateBasedBibParser]]
*/ */
class XMLPrettyPrinter {
class XMLPrettyPrinter extends ParserDelegate {
function beginFile() { function beginFile() {
header('Content-type: text/xml;'); header('Content-type: text/xml;');
print '<?xml version="1.0" encoding="'.OUTPUT_ENCODING.'"?>'; print '<?xml version="1.0" encoding="'.OUTPUT_ENCODING.'"?>';
@ -764,29 +790,6 @@ class StringEntry {
} // end class StringEntry } // end class StringEntry
/** a default empty implementation of a delegate for StateBasedBibtexParser */
class ParserDelegate {
function beginFile() {}
function endFile() {}
function setEntryField($finalkey,$entryvalue) {}
function setEntryType($entrytype) {}
function setEntryKey($entrykey) {}
function beginEntry() {}
function endEntry($entrysource) {}
/** called for each sub parts of type {part} of a field value
* for now, only CURLYTOP and CURLYONE events
*/
function entryValuePart($key, $value, $type) {}
} // end class ParserDelegate
/** builds arrays of BibEntry objects from a bibtex file. /** builds arrays of BibEntry objects from a bibtex file.
@ -794,7 +797,7 @@ usage:
<pre> <pre>
$empty_array = array(); $empty_array = array();
$db = new BibDBBuilder(); // see also factory method createBibDBBuilder $db = new BibDBBuilder(); // see also factory method createBibDBBuilder
$db->build('foo.bib'); // parses foo.bib
$db->build('bibacid-utf8.bib'); // parses bib file
print_r($db->builtdb);// an associated array key -> BibEntry objects print_r($db->builtdb);// an associated array key -> BibEntry objects
print_r($db->stringdb);// an associated array key -> strings representing @string print_r($db->stringdb);// an associated array key -> strings representing @string
</pre> </pre>
@ -1115,8 +1118,8 @@ function formatAuthor() {
/** represents a bibliographic entry. /** represents a bibliographic entry.
usage: usage:
<pre> <pre>
$db = zetDB('metrics.bib');
$entry = $db->getEntryByKey('Schmietendorf2000');
$db = zetDB('bibacid-utf8.bib');
$entry = $db->getEntryByKey('classical');
echo bib2html($entry); echo bib2html($entry);
</pre> </pre>
notes: notes:
@ -2631,7 +2634,7 @@ function splitFullName($author){
usage: usage:
<pre> <pre>
$_GET['library']=1; $_GET['library']=1;
$_GET['bib']='metrics.bib';
$_GET['bib']='bibacid-utf8.bib';
$_GET['all']=1; $_GET['all']=1;
include( 'bibtexbrowser.php' ); include( 'bibtexbrowser.php' );
setDB(); setDB();
@ -2723,7 +2726,7 @@ if (!function_exists('javascript_math')) {
/** is used for creating menus (by type, by year, by author, etc.). /** is used for creating menus (by type, by year, by author, etc.).
usage: usage:
<pre> <pre>
$db = zetDB('metrics.bib');
$db = zetDB('bibacid-utf8.bib');
$menu = new MenuManager(); $menu = new MenuManager();
$menu->setDB($db); $menu->setDB($db);
$menu->year_size=100;// should display all years :) $menu->year_size=100;// should display all years :)
@ -2979,7 +2982,7 @@ function query2title(&$query) {
/** displays the latest modified bibtex entries. /** displays the latest modified bibtex entries.
usage: usage:
<pre> <pre>
$db = zetDB('metrics.bib');
$db = zetDB('bibacid-utf8.bib');
$d = new NewEntriesDisplay(); $d = new NewEntriesDisplay();
$d->setDB($db); $d->setDB($db);
$d->setN(7);// optional $d->setN(7);// optional
@ -3015,7 +3018,7 @@ class NewEntriesDisplay {
/** displays the entries by year in reverse chronological order. /** displays the entries by year in reverse chronological order.
usage: usage:
<pre> <pre>
$db = zetDB('metrics.bib');
$db = zetDB('bibacid-utf8.bib');
$d = new YearDisplay(); $d = new YearDisplay();
$d->setDB($db); $d->setDB($db);
$d->display(); $d->display();
@ -3072,7 +3075,7 @@ class YearDisplay {
/** displays the summary information of all bib entries. /** displays the summary information of all bib entries.
usage: usage:
<pre> <pre>
$db = zetDB('metrics.bib');
$db = zetDB('bibacid-utf8.bib');
$d = new SimpleDisplay(); $d = new SimpleDisplay();
$d->setDB($db); $d->setDB($db);
$d->display(); $d->display();
@ -3237,7 +3240,7 @@ class NotFoundDisplay {
/** displays the publication records sorted by publication types (as configured by constant BIBLIOGRAPHYSECTIONS). /** displays the publication records sorted by publication types (as configured by constant BIBLIOGRAPHYSECTIONS).
usage: usage:
<pre> <pre>
$db = zetDB('metrics.bib');
$db = zetDB('bibacid-utf8.bib');
$d = new AcademicDisplay(); $d = new AcademicDisplay();
$d->setDB($db); $d->setDB($db);
$d->display(); $d->display();
@ -3324,8 +3327,8 @@ class AcademicDisplay {
/** displays a single bib entry. /** displays a single bib entry.
usage: usage:
<pre> <pre>
$db = zetDB('metrics.bib');
$dis = new BibEntryDisplay($db->getEntryByKey('Schmietendorf2000'));
$db = zetDB('bibacid-utf8.bib');
$dis = new BibEntryDisplay($db->getEntryByKey('classical'));
$dis->display(); $dis->display();
</pre> </pre>
notes: notes:
@ -3617,7 +3620,7 @@ class BibEntryDisplay {
usage: usage:
<pre> <pre>
$db = new BibDataBase(); $db = new BibDataBase();
$db->load('metrics.bib');
$db->load('bibacid-utf8.bib');
$query = array('author'=>'martin', 'year'=>2008); $query = array('author'=>'martin', 'year'=>2008);
foreach ($db->multisearch($query) as $bibentry) { echo $bibentry->getTitle(); } foreach ($db->multisearch($query) as $bibentry) { echo $bibentry->getTitle(); }
</pre> </pre>
@ -4070,9 +4073,9 @@ dd {
/** encapsulates the content of a delegate into full-fledged HTML (&lt;HTML>&lt;BODY> and TITLE) /** encapsulates the content of a delegate into full-fledged HTML (&lt;HTML>&lt;BODY> and TITLE)
usage: usage:
<pre> <pre>
$db = zetDB('metrics.bib');
$dis = new BibEntryDisplay($db->getEntryByKey('Schmietendorf2000'));
new HTMLTemplate($dis);
$db = zetDB('bibacid-utf8.bib');
$dis = new BibEntryDisplay($db->getEntryByKey('classical'));
HTMLTemplate($dis);
</pre> </pre>
* $content: an object with methods * $content: an object with methods
display() display()
@ -4156,9 +4159,9 @@ if (method_exists($content, 'getTitle')) {
/** does nothing but calls method display() on the content. /** does nothing but calls method display() on the content.
usage: usage:
<pre> <pre>
$db = zetDB('metrics.bib');
$db = zetDB('bibacid-utf8.bib');
$dis = new SimpleDisplay($db); $dis = new SimpleDisplay($db);
new NoWrapper($dis);
NoWrapper($dis);
</pre> </pre>
*/ */
function NoWrapper(&$content) { function NoWrapper(&$content) {
@ -4168,9 +4171,10 @@ function NoWrapper(&$content) {
/** is used to create an subset of a bibtex file. /** is used to create an subset of a bibtex file.
usage: usage:
<pre> <pre>
$db = zetDB('metrics.bib');
$db = zetDB('bibacid-utf8.bib');
$query = array('year'=>2005); $query = array('year'=>2005);
$dis = new BibtexDisplay()->setEntries($db->multisearch($query));
$dis = new BibtexDisplay();
$dis->setEntries($db->multisearch($query));
$dis->display(); $dis->display();
</pre> </pre>
*/ */
@ -4193,7 +4197,6 @@ class BibtexDisplay {
echo '% '.@$this->title."\n"; echo '% '.@$this->title."\n";
echo '% Encoding: '.OUTPUT_ENCODING."\n"; echo '% Encoding: '.OUTPUT_ENCODING."\n";
foreach($this->entries as $bibentry) { echo $bibentry->getText()."\n"; } foreach($this->entries as $bibentry) { echo $bibentry->getText()."\n"; }
exit;
} }
} }
@ -4203,7 +4206,7 @@ usage:
<pre> <pre>
$_GET['library']=1; $_GET['library']=1;
include( 'bibtexbrowser.php' ); include( 'bibtexbrowser.php' );
$db = zetDB('metrics.bib');
$db = zetDB('bibacid-utf8.bib');
$pd = new PagedDisplay(); $pd = new PagedDisplay();
$pd->setEntries($db->bibdb); $pd->setEntries($db->bibdb);
$pd->display(); $pd->display();
@ -4291,7 +4294,7 @@ class PagedDisplay {
/** is used to create an RSS feed. /** is used to create an RSS feed.
usage: usage:
<pre> <pre>
$db = zetDB('metrics.bib');
$db = zetDB('bibacid-utf8.bib');
$query = array('year'=>2005); $query = array('year'=>2005);
$rss = new RSSDisplay(); $rss = new RSSDisplay();
$entries = $db->getLatestEntries(10); $entries = $db->getLatestEntries(10);
@ -4388,8 +4391,7 @@ usage:
<pre> <pre>
$_GET['library']=1; $_GET['library']=1;
@require('bibtexbrowser.php'); @require('bibtexbrowser.php');
// simulating ?bib=metrics.bib&year=2009
$_GET['bib']='metrics.bib';
$_GET['bib']='bibacid-utf8.bib';
$_GET['year']='2006'; $_GET['year']='2006';
$x = new Dispatcher(); $x = new Dispatcher();
$x->main(); $x->main();

Loading…
Cancel
Save