forked from Sannis/node-mysql-libmysqlclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-all-classes-methods-tests-exists.js
executable file
·199 lines (165 loc) · 5.72 KB
/
check-all-classes-methods-tests-exists.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env node
/*
Copyright by Oleg Efimov and node-mysql-libmysqlclient contributors
See contributors list in README
See license text in LICENSE file
*/
// Require modules
var
assert = require("assert"),
util = require("util"),
fs = require("fs"),
path = require("path");
var
regex_class_source_filename =
/mysql_bindings_.*\.h$/,
regex_class_name =
/class [a-z:\s]*?([a-z]*) :[a-z:\s]*\{/i,
regex_class_methods =
/static Handle<Value> ([a-z]*)\(const Arguments& args\);/ig,
regex_class_properties_getters =
/static Handle<Value> ([a-z]*Getter)\(Local<String> property/ig,
regex_class_properties_setters =
/static Handle<Value> ([a-z]*Setter)\(Local<String> property/ig,
regex_method_is_sync =
/^(.*Sync|New)$/;
var root_dir = path.normalize(__dirname + "/..");
var source_dir = path.normalize(root_dir + "/src");
var tests_dir = path.normalize(root_dir + "/tests");
function getBindingsClasses() {
var
source_files = fs.readdirSync(source_dir),
file_content,
class_name,
classes = [],
class_method_match,
class_methods = [],
class_property_getter_match,
class_properties_getters = [],
class_property_setter_match,
class_properties_setters = [],
i;
for (i = 0; i < source_files.length; i += 1) {
console.log("Parsing " + source_files[i] + "...");
if (source_files[i].match(regex_class_source_filename)) {
file_content = fs.readFileSync(source_dir + "/" + source_files[i]).toString();
class_name = file_content.match(regex_class_name)[1];
class_properties_getters = [];
regex_class_properties_getters.lastIndex = 0;
while ((class_property_getter_match = regex_class_properties_getters.exec(file_content))) {
class_properties_getters.push(class_property_getter_match[1]);
regex_class_properties_getters.lastIndex += 1;
}
class_properties_setters = [];
regex_class_properties_setters.lastIndex = 0;
while ((class_property_setter_match = regex_class_properties_setters.exec(file_content))) {
class_properties_setters.push(class_property_setter_match[1]);
regex_class_properties_setters.lastIndex += 1;
}
class_methods = [];
regex_class_methods.lastIndex = 0;
while ((class_method_match = regex_class_methods.exec(file_content))) {
class_methods.push(class_method_match[1]);
regex_class_methods.lastIndex += 1;
}
classes.push({
name: class_name,
properties_getters: class_properties_getters,
properties_setters: class_properties_setters,
methods: class_methods
});
}
}
classes.sort(function (a, b) {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
return classes;
}
var red = function (str) {
return "\u001b[31m" + str + "\u001b[39m";
};
var green = function (str) {
return "\u001b[32m" + str + "\u001b[39m";
};
var bold = function (str) {
return "\u001b[1m" + str + "\u001b[22m";
};
var
bindings_classes = getBindingsClasses(),
i, j,
test_file_name,
test_require,
notexist_tests = 0;
for (i = 0; i < bindings_classes.length; i += 1) {
test_file_name_sync = tests_dir + "/low-level-sync/test-class-" + bindings_classes[i].name.toLowerCase() + "-sync.js";
console.log(bold(bindings_classes[i].name + ": " + path.relative(root_dir, test_file_name_sync)));
try {
test_require_sync = require(test_file_name_sync.replace(/\.js$/, ''));
}
catch (e) {
test_require_sync = false;
}
for (j = 0; j < bindings_classes[i].properties_getters.length; j += 1) {
if (test_require_sync
&& (typeof test_require_sync[bindings_classes[i].properties_getters[j]] !== 'undefined')
) {
console.log(green('✔ ' + bindings_classes[i].properties_getters[j]));
} else {
console.log(red('✖ ' + bindings_classes[i].properties_getters[j]));
notexist_tests += 1;
}
}
for (j = 0; j < bindings_classes[i].properties_setters.length; j += 1) {
if (test_require_sync
&& (typeof test_require_sync[bindings_classes[i].properties_setters[j]] !== 'undefined')
) {
console.log(green('✔ ' + bindings_classes[i].properties_setters[j]));
} else {
console.log(red('✖ ' + bindings_classes[i].properties_setters[j]));
notexist_tests += 1;
}
}
for (j = 0; j < bindings_classes[i].methods.length; j += 1) {
if (bindings_classes[i].methods[j].match(regex_method_is_sync)) {
if (test_require_sync
&& (typeof test_require_sync[bindings_classes[i].methods[j]] !== 'undefined')
) {
console.log(green('✔ ' + bindings_classes[i].methods[j]));
} else {
console.log(red('✖ ' + bindings_classes[i].methods[j]));
notexist_tests += 1;
}
}
}
test_file_name = tests_dir + "/low-level-async/test-class-" + bindings_classes[i].name.toLowerCase() + "-async.js";
console.log(bold(bindings_classes[i].name + ": " + path.relative(root_dir, test_file_name)));
try {
test_require = require(test_file_name.replace(/\.js$/, ''));
}
catch (e) {
test_require = false;
}
for (j = 0; j < bindings_classes[i].methods.length; j += 1) {
if (!bindings_classes[i].methods[j].match(regex_method_is_sync)) {
if (test_require
&& (typeof test_require[bindings_classes[i].methods[j]] !== 'undefined')
) {
console.log(green('✔ ' + bindings_classes[i].methods[j]));
} else {
console.log(red('✖ ' + bindings_classes[i].methods[j]));
notexist_tests += 1;
}
}
}
}
if (notexist_tests) {
console.log('\n' + bold(red('NONEXISTENT METHODS TESTS: ')) + notexist_tests);
} else {
console.log('\n' + bold(green('OK')));
}