diff --git a/fish_shell/fish_settings.c b/fish_shell/fish_settings.c index 0eb5cab..a39c3bd 100644 --- a/fish_shell/fish_settings.c +++ b/fish_shell/fish_settings.c @@ -28,7 +28,9 @@ Settings *getSettings() { filename = strcat(filename, (char*) FISH_RC_FILE); s->passwd = user; s->PS1 = extractVariable(filename, (char*) "PS1"); + if (s->PS1 == NULL) s->PS1 = strdup("->"); s->PS2 = extractVariable(filename, (char*) "PS2"); + if (s->PS2 == NULL) s->PS2 = strdup("->"); free(filename); return s; @@ -36,6 +38,8 @@ Settings *getSettings() { void freeSettings(Settings *settings){ if (settings != NULL){ + settings->PS1[0] = '\0'; + settings->PS2[0] = '\0'; free(settings->PS1); free(settings->PS2); free(settings); @@ -73,7 +77,7 @@ char* extractVariable(char* filename, char* var){ else { perror ( filename ); /* why didn't the file open? */ } - return NULL; + return tmp; } diff --git a/fish_shell/fish_settings.h b/fish_shell/fish_settings.h index 91b7792..eac5988 100644 --- a/fish_shell/fish_settings.h +++ b/fish_shell/fish_settings.h @@ -10,4 +10,5 @@ Settings * getSettings(); //TESTEDssssss void freeSettings(Settings *settings); //TESTED char* extractVariable(char* filename, char* var);//TESTED -#endif //FISH_FISH_SETTINGS_H \ No newline at end of file +#endif //FISH_FISH_SETTINGS_H + diff --git a/fish_shell_tests/FishSettingsTests.cpp b/fish_shell_tests/FishSettingsTests.cpp index 70718d7..b2c122a 100644 --- a/fish_shell_tests/FishSettingsTests.cpp +++ b/fish_shell_tests/FishSettingsTests.cpp @@ -3,14 +3,13 @@ #include "../fish_shell/fish_settings.h" TEST(free_settings_Test, freeSettings){ - Settings *s1 = getSettings(); - Settings *s2 = getSettings(); + Settings *s = getSettings(); - freeSettings(s1); + ASSERT_STREQ(s->PS1, "->"); - ASSERT_STRNE(s1->PS1, s2->PS1); + freeSettings(s); - freeSettings(s2); + ASSERT_STRNE(s->PS1, "->"); } TEST(extract_variable_Test, extractVariable){ @@ -25,4 +24,4 @@ TEST(get_settings_Test, getSettings){ ASSERT_FALSE(s ==NULL); ASSERT_FALSE(s->passwd == NULL); freeSettings(s); -} \ No newline at end of file +} diff --git a/fish_shell_tests/fishrc b/fish_shell_tests/fishrc new file mode 100644 index 0000000..dcc591a --- /dev/null +++ b/fish_shell_tests/fishrc @@ -0,0 +1,2 @@ +PS1=sli-> +PS2=sony