Skip to content

Commit

Permalink
fix/input empty string (#51)
Browse files Browse the repository at this point in the history
* fix

* add test
  • Loading branch information
rask24 committed Mar 27, 2024
1 parent 412c874 commit cd75ff2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/initialization/check_args.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 14:44:55 by reasuke #+# #+# */
/* Updated: 2024/02/20 14:19:12 by reasuke ### ########.fr */
/* Updated: 2024/03/27 13:07:53 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -20,8 +20,9 @@ static bool _has_not_digit(int argc, char **argv)
i = 1;
while (i < argc)
{
errno = 0;
ft_strtol(argv[i], &end_ptr, 10);
if (*end_ptr)
if (*end_ptr || errno)
return (true);
i++;
}
Expand Down
8 changes: 8 additions & 0 deletions test/unit/test_check_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ TEST(check_args, OneArgumentNonDigit) {
EXPECT_EXIT(check_args(argc, argv), ::testing::ExitedWithCode(1), "Error\n");
}

TEST(check_args, OneArgumentEmptyString) {
int argc = 2;
const char *args[] = {"push_swap", ""};
char **argv = const_cast<char **>(args);

EXPECT_EXIT(check_args(argc, argv), ::testing::ExitedWithCode(1), "Error\n");
}

TEST(check_args, OneArgumentIncludingNonDigit) {
int argc = 2;
const char *args[] = {"push_swap", "42abc"};
Expand Down

0 comments on commit cd75ff2

Please sign in to comment.