forked from zotero/citeproc-js-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
testciteproc.js
184 lines (170 loc) · 4.63 KB
/
testciteproc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
var fs = require('fs');
var assert = require('assert');
var repl = require('repl');
var CSL = require("./citeprocmodule").CSL;
var nt = require('./stdNodeTest');
var zotero = require("./zoteronode").zotero;
zotero.DebugEnabled = 0;
var tests = fs.readdirSync("./citeproc-js/tests/fixtures/run/machines");
tests.sort();
var print = '';
var testsRun = 0;
var testsPassed = 0;
var nodeTests = [];
var bundleStrings = [
'abbrevs',
'affix',
'api',
'bibheader',
'bibsection',
'bugreports',
'citeprocjs',
'collapse',
'condition',
'date',
'decorations',
'disambiguate',
'discretionary',
'display',
'eclac',
'flipflop',
'form',
'fullstyles',
'group',
'institutions',
'integration',
'label',
'locale',
'locators',
'magic',
'multilingual',
'name_',
'nameattr',
'nameorder',
'namespaces',
'number',
'page',
'parallel',
'plural',
'position',
'quotes',
'simplespace',
'sort',
'textcase',
'unicode',
'variables'];
var runTest = function(nodeTest){
try{
assert.equal(nodeTest.run(), nodeTest.result, "unexpected test result in test " + nodeTest.myname);
testsPassed += 1;
console.log(nodeTest.myname + " run successfully");
nodeTest = null;
}
catch(err){
console.log("Exception thrown from test " + nodeTest.myname);
if(typeof err == "string"){
console.log("Caught exception: " + err);
}
else if(err.name == "AssertionError"){
print = "Assertion Failed\n";
print += "Message: " + err.message + "\n";
print += "expected:\n" + err.expected + "\n";
print += "returned:\n" + err.actual + "\n";
console.log(print);
// console.log(nodeTest.test.csl);
}
else{
print = 'Caught exception: ' + err.name + " : " + err.message + "\n";
print += err.stack;
console.log(print);
}
//var context = {'t': nodeTest, "zotero": zotero};
//repl.start().context.a = context;
}
};
var runBundle = function(prefixre, tests){
var nodeTests = [];
for(var i = 0; i < tests.length; i++){
var testname = tests[i].replace(".json", '');
if(prefixre.test(tests[i])){
nodeTests.push(new nt.StdNodeTest(CSL, testname));
}
}
for(var i = 0; i < nodeTests.length; i++){
runTest(nodeTests[i]);
}
};
var mode = 0;
for(var i = 2; i < process.argv.length; i++){
switch(process.argv[i]){
case "--bundle":
mode = 1;
var prefix = process.argv[i+1];
var prefixre = new RegExp('^' + prefix);
i++;
runBundle(prefixre, tests);
break;
case "--test":
mode = 2;
var argTestName = process.argv[i+1];
i++;
nodeTest = new nt.StdNodeTest(CSL, argTestName);
runTest(nodeTest);
break;
case "--debug":
zotero.DebugEnabled = 1;
break;
}
}
if(mode == 0){
for(var i = 0; i < bundleStrings.length; i++){
var re = new RegExp('^' + bundleStrings[i]);
runBundle(re, tests);
}
}
/*
for(var i = 0; i < tests.length; i++){
var testname = tests[i].replace(".json", '');
if(prefixre){
if(prefixre.test(tests[i])){
nodeTests.push(new nt.StdNodeTest(CSL, testname));
}
}
else if(argTestName && argTestName == testname){
nodeTests.push(new nt.StdNodeTest(CSL, testname));
break;
}
}
for(var i = 0; i < nodeTests.length; i++){
}
*/
/*
for(var i = 0; i < tests.length; i++){
var testname = tests[i].replace(".json", '');
var test = new nt.StdNodeTest(CSL, testname);
try{
assert.equal(test.result, test.run(), "unexpected test result in test " + testname);
passed += 1;
console.log(testname + " run successfully");
}
catch(err){
if(typeof err == "string"){
console.log("Caught exception: " + err);
}
else if(err.name == "AssertionError"){
print = "Assertion Failed\n";
print += "Message: " + err.message + "\n";
print += "expected:\n" + err.expected + "\n";
print += "returned:\n" + err.actual + "\n";
console.log(print);
}
else{
print = 'Caught exception: ' + err.name + " : " + err.message + "\n";
print += err.stack;
console.log(print);
}
}
}
*/
//console.log("Total tests: " + test.length);
//console.log("Tests Passed: " + passed);