Skip to content

Commit

Permalink
Added ability to save test results
Browse files Browse the repository at this point in the history
This makes it easy to update the test data
  • Loading branch information
Jeremy Ruston committed Mar 29, 2012
1 parent 392e717 commit 0c2ba36
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions tiddlywiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ var commandLineSwitches = {
}
},
wikitest: {
args: {min: 1, max: 1},
args: {min: 1, max: 2},
handler: function(args,callback) {
var testdirectory = args[0],
saveResults = args[1] === "save",
files = fs.readdirSync(testdirectory),
titles = [],
f,t,extname,basename;
Expand All @@ -213,16 +214,25 @@ var commandLineSwitches = {
}
}
for(t=0; t<titles.length; t++) {
var htmlTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".html"),"utf8"),
plainTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".txt"),"utf8"),
var htmlFilename = path.resolve(testdirectory,titles[t] + ".html"),
plainFilename = path.resolve(testdirectory,titles[t] + ".txt"),
htmlTarget = fs.readFileSync(htmlFilename,"utf8"),
plainTarget = fs.readFileSync(plainFilename,"utf8"),
tiddler = app.store.getTiddler(titles[t]),
htmlRender = app.store.renderTiddler("text/html",titles[t]),
plainRender = app.store.renderTiddler("text/plain",titles[t]);
if(htmlTarget !== htmlRender) {
console.error("Tiddler %s html error\nTarget: %s\nFound: %s\n",titles[t],htmlTarget,htmlRender);
}
if(plainTarget !== plainRender) {
console.error("Tiddler %s plain text error\nTarget: %s\nFound: %s\n",titles[t],plainTarget,plainRender);
if(saveResults) {
// Save results
fs.writeFileSync(htmlFilename,htmlRender,"utf8");
fs.writeFileSync(plainFilename,plainRender,"utf8");
} else {
// Report results
if(htmlTarget !== htmlRender) {
console.error("Tiddler %s html error\nTarget: %s\nFound: %s\n",titles[t],htmlTarget,htmlRender);
}
if(plainTarget !== plainRender) {
console.error("Tiddler %s plain text error\nTarget: %s\nFound: %s\n",titles[t],plainTarget,plainRender);
}
}
}
}
Expand Down

0 comments on commit 0c2ba36

Please sign in to comment.