MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / test

Function test

modules/gdscript/tests/test_gdscript.cpp:305–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

303}
304
305void test(TestType p_type) {
306 List<String> cmdlargs = OS::get_singleton()->get_cmdline_args();
307
308 if (cmdlargs.is_empty()) {
309 return;
310 }
311
312 String test = cmdlargs.back()->get();
313 if (!test.ends_with(".gd") && !test.ends_with(".gdc")) {
314 print_line("This test expects a path to a GDScript file as its last parameter. Got: " + test);
315 return;
316 }
317
318 Ref<FileAccess> fa = FileAccess::open(test, FileAccess::READ);
319 ERR_FAIL_COND_MSG(fa.is_null(), "Could not open file: " + test);
320
321 // Initialize the language for the test routine.
322 init_language(fa->get_path_absolute().get_base_dir());
323
324 // Load global classes.
325 TypedArray<Dictionary> script_classes = ProjectSettings::get_singleton()->get_global_class_list();
326 for (int i = 0; i < script_classes.size(); i++) {
327 Dictionary c = script_classes[i];
328 if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base") || !c.has("is_abstract") || !c.has("is_tool")) {
329 continue;
330 }
331 ScriptServer::add_global_class(c["class"], c["base"], c["language"], c["path"], c["is_abstract"], c["is_tool"]);
332 }
333
334 Vector<uint8_t> buf;
335 uint64_t flen = fa->get_length();
336 buf.resize(flen + 1);
337 fa->get_buffer(buf.ptrw(), flen);
338 buf.write[flen] = 0;
339
340 String code = String::utf8((const char *)&buf[0]);
341
342 Vector<String> lines;
343 int last = 0;
344 for (int i = 0; i <= code.length(); i++) {
345 if (code[i] == '\n' || code[i] == 0) {
346 lines.push_back(code.substr(last, i - last));
347 last = i + 1;
348 }
349 }
350
351 switch (p_type) {
352 case TEST_TOKENIZER:
353 test_tokenizer(code, lines);
354 break;
355 case TEST_TOKENIZER_BUFFER:
356 if (test.ends_with(".gdc")) {
357 test_tokenizer_buffer(buf, lines);
358 } else {
359 test_tokenizer_buffer(code, lines);
360 }
361 break;
362 case TEST_PARSER:

Callers 5

test_tokenizerFunction · 0.50
test_tokenizer_bufferFunction · 0.50
test_parserFunction · 0.50
test_compilerFunction · 0.50
test_bytecodeFunction · 0.50

Calls 15

print_lineFunction · 0.85
init_languageFunction · 0.85
finish_languageFunction · 0.85
ends_withMethod · 0.80
get_base_dirMethod · 0.80
substrMethod · 0.80
test_tokenizerFunction · 0.70
test_tokenizer_bufferFunction · 0.70
test_parserFunction · 0.70
test_compilerFunction · 0.70
sizeMethod · 0.65
get_cmdline_argsMethod · 0.45

Tested by

no test coverage detected