-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathgenerate-php-src-tests.js
More file actions
executable file
·190 lines (178 loc) · 7.03 KB
/
generate-php-src-tests.js
File metadata and controls
executable file
·190 lines (178 loc) · 7.03 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
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
#!/usr/bin/env node
const fs = require("fs");
const glob = require("glob");
// Note: Ideally we'd check for "--EXPECTF--" in the phpt file, but that also
// described run-time errors, rather than just parse errors.
const testsThatExpectParseErrors = [
"Zend/tests/attributes/019_variable_attribute_name.phpt",
"Zend/tests/bug43343.phpt",
"Zend/tests/bug60099.phpt",
"Zend/tests/bug64660.phpt",
"Zend/tests/bug70430.phpt",
"Zend/tests/bug76439_2.phpt",
"Zend/tests/bug77993.phpt",
"Zend/tests/bug78363.phpt",
"Zend/tests/bug78454_1.phpt",
"Zend/tests/bug78454_2.phpt",
"Zend/tests/ctor_promotion_additional_modifiers.phpt",
"Zend/tests/flexible-heredoc-error1.phpt",
"Zend/tests/flexible-heredoc-error10.phpt",
"Zend/tests/flexible-heredoc-error11.phpt",
"Zend/tests/flexible-heredoc-error12.phpt",
"Zend/tests/flexible-heredoc-error13.phpt",
"Zend/tests/flexible-heredoc-error2.phpt",
"Zend/tests/flexible-heredoc-error3.phpt",
"Zend/tests/flexible-heredoc-error4.phpt",
"Zend/tests/flexible-heredoc-error5.phpt",
"Zend/tests/flexible-heredoc-error6.phpt",
"Zend/tests/flexible-heredoc-error7.phpt",
"Zend/tests/flexible-heredoc-error8.phpt",
"Zend/tests/flexible-heredoc-error9.phpt",
"Zend/tests/flexible-nowdoc-error1.phpt",
"Zend/tests/flexible-nowdoc-error2.phpt",
"Zend/tests/flexible-nowdoc-error3.phpt",
"Zend/tests/flexible-nowdoc-error4.phpt",
"Zend/tests/flexible-nowdoc-error5.phpt",
"Zend/tests/flexible-nowdoc-error6.phpt",
"Zend/tests/flexible-nowdoc-error7.phpt",
"Zend/tests/flexible-nowdoc-error8.phpt",
"Zend/tests/function_arguments/call_with_leading_comma_error.phpt",
"Zend/tests/function_arguments/call_with_multi_inner_comma_error.phpt",
"Zend/tests/function_arguments/call_with_multi_trailing_comma_error.phpt",
"Zend/tests/function_arguments/call_with_only_comma_error.phpt",
"Zend/tests/function_arguments_001.phpt",
"Zend/tests/function_arguments_002.phpt",
"Zend/tests/grammar/bug78441.phpt",
"Zend/tests/grammar/regression_004.phpt",
"Zend/tests/grammar/regression_005.phpt",
"Zend/tests/grammar/regression_010.phpt",
"Zend/tests/grammar/regression_012.phpt",
"Zend/tests/heredoc_005.phpt",
"Zend/tests/heredoc_013.phpt",
"Zend/tests/heredoc_014.phpt",
"Zend/tests/list_011.phpt",
"Zend/tests/lsb_008.phpt",
"Zend/tests/lsb_009.phpt",
"Zend/tests/namespace_name_namespace_start.phpt",
"Zend/tests/namespaced_name_whitespace.phpt",
"Zend/tests/ns_088.phpt",
"Zend/tests/ns_094.phpt",
"Zend/tests/ns_096.phpt",
"Zend/tests/ns_trailing_comma_error_01.phpt",
"Zend/tests/ns_trailing_comma_error_02.phpt",
"Zend/tests/ns_trailing_comma_error_03.phpt",
"Zend/tests/ns_trailing_comma_error_04.phpt",
"Zend/tests/ns_trailing_comma_error_05.phpt",
"Zend/tests/ns_trailing_comma_error_06.phpt",
"Zend/tests/ns_trailing_comma_error_07.phpt",
"Zend/tests/ns_trailing_comma_error_08.phpt",
"Zend/tests/numeric_literal_separator_002.phpt",
"Zend/tests/numeric_literal_separator_003.phpt",
"Zend/tests/numeric_literal_separator_004.phpt",
"Zend/tests/numeric_literal_separator_005.phpt",
"Zend/tests/numeric_literal_separator_006.phpt",
"Zend/tests/numeric_literal_separator_007.phpt",
"Zend/tests/numeric_literal_separator_008.phpt",
"Zend/tests/numeric_literal_separator_009.phpt",
"Zend/tests/oct_whitespace.phpt",
"Zend/tests/readonly_classes/readonly_enum.phpt",
"Zend/tests/readonly_classes/readonly_interface.phpt",
"Zend/tests/readonly_classes/readonly_trait.phpt",
"Zend/tests/short_echo_as_identifier.phpt",
"Zend/tests/traits/bug55524.phpt",
"Zend/tests/traits/bugs/interfaces.phpt",
"Zend/tests/type_declarations/intersection_types/invalid_types/invalid_nullable_type.phpt",
"Zend/tests/type_declarations/intersection_types/parse_error.phpt",
"Zend/tests/type_declarations/intersection_types/parse_error.phpt",
"Zend/tests/type_declarations/mixed/casting/mixed_cast_error.phpt",
"Zend/tests/type_declarations/static_type_param.phpt",
"Zend/tests/type_declarations/static_type_property.phpt",
"Zend/tests/type_declarations/typed_properties_025.phpt",
"Zend/tests/unterminated_comment.phpt",
"Zend/tests/varSyntax/globalNonSimpleVariableError.phpt",
"tests/classes/constants_error_006.phpt",
"tests/classes/constants_error_007.phpt",
"tests/lang/019.phpt",
"tests/lang/bug21669.phpt",
"tests/lang/bug21820.phpt",
"tests/lang/bug71897.phpt",
"tests/lang/invalid_octal.phpt",
"tests/lang/string/unicode_escape_empty.phpt",
"tests/lang/string/unicode_escape_incomplete.phpt",
"tests/lang/string/unicode_escape_large_codepoint.phpt",
"tests/lang/string/unicode_escape_sign.phpt",
"tests/lang/string/unicode_escape_sign2.phpt",
"tests/lang/string/unicode_escape_whitespace.phpt",
// These should also throw parse errors according to PHP 8.1, but we also
// support older versions.
// "Zend/tests/real_cast.phpt",
// These are not parse errors in PHP strictly speaking, but they test syntax
// that is still invalid (i.e. it generates a fatal error).
"Zend/tests/enum/case-in-class.phpt",
"Zend/tests/enum/no-name-property.phpt",
"Zend/tests/enum/no-properties.phpt",
"Zend/tests/errmsg_001.phpt",
"Zend/tests/readonly_props/readonly_const.phpt",
"Zend/tests/readonly_props/readonly_method.phpt",
"Zend/tests/readonly_props/readonly_method_trait.phpt",
"Zend/tests/static_in_trait_insteadof_list.phpt",
"Zend/tests/variadic/only_last_error.phpt",
];
const header = `// eslint-disable prettier/prettier
const parser = require("../main");
describe("php-src tests", function () {`;
const footer = `});
`;
for (const absolutePath of glob.sync(
__dirname + "/../php-src/{tests,Zend,ext/standard}/**/*.phpt"
)) {
const relativePath = absolutePath.substring(
absolutePath.indexOf("php-src") + "php-src/".length
);
const testName = [];
const testContents = [];
const expectError = testsThatExpectParseErrors.includes(relativePath);
let testFileName = relativePath.replace(/[/\\]/g, "-");
testFileName = testFileName.substring(0, testFileName.lastIndexOf("."));
let section = null;
for (const line of fs
.readFileSync(absolutePath)
.toString()
.split(/[\r\n]+/)) {
if (/^--\w/.test(line)) {
if (line === "--TEST--") {
section = "name";
} else if (line === "--FILE--") {
section = "file";
} else {
section = null;
}
continue;
}
if (section === "name") {
testName.push(line);
} else if (section === "file") {
testContents.push(line);
}
// TODO: Handle --FILE_EXTERNAL--
}
if (testContents.length === 0) {
continue;
}
const contents = `${header}
// ${relativePath}
it(${JSON.stringify(testName.join("\n"))}, function () {
expect(${expectError ? "() => " : ""}parser.parseCode(${JSON.stringify(
testContents.join("\n")
)})).${expectError ? "toThrowErrorMatchingSnapshot" : "toMatchSnapshot"}();
});
${footer}`;
fs.writeFile(
`${__dirname}/../test/php-src/${testFileName}.test.js`,
contents,
(err) => {
if (err) throw err;
console.log(`Written ${testFileName}`);
}
);
}