forked from AgustinSRG/Pokemon-Showdown-Node-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
150 lines (126 loc) · 3.2 KB
/
test.js
File metadata and controls
150 lines (126 loc) · 3.2 KB
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
/*
Test Script
*/
const MAX_COMMAND_RECURSION = 10;
function test (str) {
console.log("test".cyan + "\t" + str);
}
function warn (str) {
console.log("warn".yellow + "\t" + str);
}
/*
* Features test
*/
test("Starting features test");
var featureList = fs.readdirSync('./features/');
var featureErr = false;
featureList.forEach(function (feature) {
if (fs.existsSync('./features/' + feature + '/index.js')) {
try {
var f = require('./features/' + feature + '/index.js');
if (f.id) {
Features[f.id] = f;
ok("New feature: " + f.id + ' | ' + f.desc);
} else {
error("Feature " + './features/' + feature + " does not have an id");
featureErr = true;
}
} catch (e) {
errlog(e.stack);
error("Failed to load feature: " + './features/' + feature);
featureErr = true;
}
}
});
for (var f in Features) {
try {
if (typeof Features[f].destroy === "function") {
Features[f].destroy();
debug("destroyed feature " + f);
} else {
delete Features[f];
}
} catch (e) {
errlog(e.stack);
error("Failed to destroy feature: " + f);
featureErr = true;
}
}
if (featureErr) {
error("features test failed. See above for details.");
process.exit(1);
}
/*
* Command Test
* -Test if some commands are repeated
* -Test if some commands are invalid (not functions or references)
*/
test("Starting command test");
CommandParser.loadCommands();
var cmderr = false;
var commands = CommandParser.commands, cmdaux = {}, tempcmds = {};
fs.readdirSync('./commands').forEach(function (file) {
if (file.substr(-3) === '.js') {
try {
tempcmds = require('./commands/' + file).commands;
} catch (e) {
errlog(e.stack);
error("Could not import commands file: ./commands/" + file);
cmderr = true;
return;
}
for (var c in tempcmds) {
if (c.toLowerCase() !== c) {
warn("Command key \"" + c + "\" contains uppercase letters, whitch are not supported. See: " + file);
cmderr = true;
}
if (cmdaux[c]) {
cmdaux[c].push(file);
warn("Command \"" + c + "\" is repeated: " + cmdaux[c].join(', '));
cmderr = true;
} else {
cmdaux[c] = [];
cmdaux[c].push(file);
}
var handler = c;
var loopBreaker = 0;
while (typeof commands[handler] === 'string' && (loopBreaker++ < MAX_COMMAND_RECURSION)) {
handler = commands[handler];
}
if (typeof commands[handler] !== 'function') {
error("invalid command type: " + c + ' (' + handler + ')' + ' = ' + sys.inspect(commands[handler]));
cmderr = true;
}
}
}
});
if (cmderr) {
error("command test failed. See above for details.");
process.exit(1);
}
/*
* Languages Test
*/
test("Starting languages test");
Tools.loadTranslations();
var defaultLang = Config.language || "english";
if (!Tools.translations[defaultLang]) {
error("language test failed. Default language was not found: " + defaultLang);
process.exit(1);
}
var langErr = false;
for (var k in Tools.translations[defaultLang]) {
for (var l in Tools.translations) {
if (!Tools.translations[l][k]) {
warn("Key \"" + k + "\" not found in " + l + " language");
langErr = true;
}
}
}
if (langErr) {
error("language test failed. See above for details.");
process.exit(1);
}
/* Test passed */
ok("Test script passed");
process.exit();