mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
Fixed a bug where help("modules") crashed when no lib was loaded
This commit is contained in:
parent
fa5ea67ba8
commit
cefa730d35
@ -2427,6 +2427,10 @@ PikaObj* obj_linkLibrary(PikaObj* self, uint8_t* library_bytes) {
|
||||
|
||||
void obj_printModules(PikaObj* self) {
|
||||
LibObj* lib = obj_getObj(self, "@lib");
|
||||
if (lib == NULL) {
|
||||
pika_platform_printf("Error: Not found LibObj, please execute obj_linkLibrary()\r\n");
|
||||
return;
|
||||
}
|
||||
pika_platform_printf(arg_getStr((Arg*)g_PikaObjState.helpModulesCmodule));
|
||||
LibObj_printModules(lib);
|
||||
}
|
||||
|
@ -3054,4 +3054,20 @@ TEST(pikaMain, _obj_set_str_null) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(pikaMain, shell_nolib_print_help) {
|
||||
char lines[] = {"help(\"modules\")\n"};
|
||||
/* init */
|
||||
g_PikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
for (size_t i = 0; i < strGetSize(lines); i++) {
|
||||
obj_runChar(pikaMain, lines[i]);
|
||||
}
|
||||
/* assert */
|
||||
EXPECT_STREQ(log_buff[1], "Error: Not found LibObj, please execute obj_linkLibrary()\r\n");
|
||||
/* deinit */
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST_END
|
Loading…
x
Reference in New Issue
Block a user