Cscott has uploaded a new change for review. https://gerrit.wikimedia.org/r/50617
Change subject: Update cache file if parserTests parser or .txt is updated (take 2). ...................................................................... Update cache file if parserTests parser or .txt is updated (take 2). This is a better solution than the fix already merged in e348d00e3314d5b0ee6b7ce3d813f84baea6d594 -- it uses the existing fileDependencies[] and CACHE mechanism of ParserTests.getTests(). Also fixes a bug where the cache file was written to the cwd, not the __dirname directory (ie js/tests), and adds the cache file and the parser tests to .gitignore. Change-Id: I051349612e9a23a9aaf8a534161c80dfcae8db96 --- M .gitignore M js/tests/parserTests.js M js/tests/runtests.sh 3 files changed, 21 insertions(+), 20 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid refs/changes/17/50617/1 diff --git a/.gitignore b/.gitignore index ea87853..f6a90b5 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ js/api/nohup.out js/api/npm-debug.log js/node_modules/ +js/tests/parserTests.cache +js/tests/parserTests.txt diff --git a/js/tests/parserTests.js b/js/tests/parserTests.js index 08905d5..ce4b496 100644 --- a/js/tests/parserTests.js +++ b/js/tests/parserTests.js @@ -237,26 +237,29 @@ } catch (e) { console.log( e ); } + // parser grammar is also a dependency + fileDependencies.push( this.testParserFileName ); + if( !argv.cache ) { // Cache not wanted, parse file and return object return this.parseTestCase( testFile ); } - // Find out modification time of all files depencies and then hashes those - // as a unique value using sha1. - var mtimes = ''; - fileDependencies.sort().forEach( function (file) { - mtimes += fs.statSync( file ).mtime; - }); + // Find out modification time of all files dependencies and then hash those + // to make a unique value using sha1. + var mtimes = fileDependencies.sort().map( function (file) { + return fs.statSync( file ).mtime; + }).join('|'); var sha1 = require('crypto').createHash('sha1') .update( mtimes ).digest( 'hex' ), + cache_file_name= __dirname + '/' + this.cache_file, // Look for a cache_file cache_content, cache_file_digest; try { console.log( "Looking for cache file " + this.cache_file ); - cache_content = fs.readFileSync( this.cache_file, 'utf8' ); + cache_content = fs.readFileSync( cache_file_name, 'utf8' ); // Fetch previous digest cache_file_digest = cache_content.match( /^CACHE: (\w+)\n/ )[1]; } catch( e4 ) { @@ -265,16 +268,16 @@ if( cache_file_digest === sha1 ) { // cache file match our digest. - console.log( "Loaded tests cases from cache file" ); + console.log( "Loaded test cases from cache file" ); // Return contained object after removing first line (CACHE: <sha1>) return JSON.parse( cache_content.replace( /.*\n/, '' ) ); } else { // Write new file cache, content preprended with current digest - console.log( "Cache file either inexistant or outdated" ); + console.log( "Cache file either not present or outdated" ); var parse = this.parseTestCase( testFile ); if ( parse !== undefined ) { console.log( "Writing parse result to " + this.cache_file ); - fs.writeFileSync( this.cache_file, + fs.writeFileSync( cache_file_name, "CACHE: " + sha1 + "\n" + JSON.stringify( parse ), 'utf8' ); @@ -1045,7 +1048,8 @@ } try { - this.testParser = PEG.buildParser( fs.readFileSync( __dirname + '/parserTests.pegjs', 'utf8' ) ); + this.testParserFileName = __dirname + '/parserTests.pegjs'; + this.testParser = PEG.buildParser( fs.readFileSync( this.testParserFileName, 'utf8' ) ); } catch ( e2 ) { console.log( e2 ); } diff --git a/js/tests/runtests.sh b/js/tests/runtests.sh index 158b16f..7fcee7b 100755 --- a/js/tests/runtests.sh +++ b/js/tests/runtests.sh @@ -27,30 +27,25 @@ fi node=` ( nodejs --version > /dev/null 2>&1 && echo 'nodejs' ) || echo 'node' ` -cache=--cache -if [ parserTests.pegjs -nt parserTests.cache -o \ - parserTests.txt -nt parserTests.cache ]; then - cache= -fi if [ "$1" = "--wt2wt" ];then OUTPUT="results/roundtrip.txt" - time $node parserTests.js $cache --wt2wt \ + time $node parserTests.js --cache --wt2wt \ > $OUTPUT 2>&1 TEST_EXIT_CODE=$? elif [ "$1" = '--selser' ];then OUTPUT="results/selser.txt" - time $node parserTests.js --selser --changesin selser.changes.json $cache --printwhitelist \ + time $node parserTests.js --selser --changesin selser.changes.json --cache --printwhitelist \ > $OUTPUT 2>&1 TEST_EXIT_CODE=$? elif [ "$1" = '--wt2html' ];then OUTPUT="results/html.txt" - time $node parserTests.js --wt2html $cache --printwhitelist \ + time $node parserTests.js --wt2html --cache --printwhitelist \ > $OUTPUT 2>&1 TEST_EXIT_CODE=$? else OUTPUT="results/all.txt" - time $node parserTests.js --wt2html --wt2wt --html2html --selser --changesin selser.changes.json $cache --printwhitelist \ + time $node parserTests.js --wt2html --wt2wt --html2html --selser --changesin selser.changes.json --cache --printwhitelist \ > $OUTPUT 2>&1 TEST_EXIT_CODE=$? fi -- To view, visit https://gerrit.wikimedia.org/r/50617 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I051349612e9a23a9aaf8a534161c80dfcae8db96 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Parsoid Gerrit-Branch: master Gerrit-Owner: Cscott <wikime...@cscott.net> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits