if (argc >= 1 && grub_strcmp (args[argc - 1], "]") == 0)
argc--;
- return test_parse (args, &argn, argc) ? GRUB_ERR_NONE
- : grub_error (GRUB_ERR_TEST_FAILURE, "false");
+ return test_parse (args, &argn, argc) ? 0 : 1;
}
static grub_command_t cmd_1, cmd_2;
check_SCRIPTS += grub_script_for1
grub_script_for1_SOURCES = tests/grub_script_for1.in
+check_SCRIPTS += grub_script_while1
+grub_script_while1_SOURCES = tests/grub_script_while1.in
+
# List of tests to execute on "make check"
# SCRIPTED_TESTS = example_scripted_test
# SCRIPTED_TESTS += example_grub_script_test
SCRIPTED_TESTS += grub_script_echo_keywords
SCRIPTED_TESTS += grub_script_vars1
SCRIPTED_TESTS += grub_script_for1
+SCRIPTED_TESTS += grub_script_while1
# dependencies between tests and testing-tools
$(SCRIPTED_TESTS): grub-shell grub-shell-tester
#include <grub/lib/arg.h>
#include <grub/normal.h>
+/* Max digits for a char is 3 (0xFF is 255), similarly for an int it
+ is sizeof (int) * 3, and one extra for a possible -ve sign. */
+#define ERRNO_DIGITS_MAX (sizeof (int) * 3 + 1)
+
static grub_err_t
grub_script_execute_cmd (struct grub_script_cmd *cmd)
{
+ int ret;
+ char errnobuf[ERRNO_DIGITS_MAX + 1];
+
if (cmd == 0)
return 0;
- return cmd->exec (cmd);
+ ret = cmd->exec (cmd);
+
+ grub_snprintf (errnobuf, sizeof (errnobuf), "%d", ret);
+ grub_env_set ("?", errnobuf);
+ return ret;
}
/* Expand arguments in ARGLIST into multiple arguments. */
grub_err_t ret = 0;
int argcount = 0;
grub_script_function_t func = 0;
- char errnobuf[18];
char *cmdname;
/* Lookup the command. */
grub_env_set (assign, eq);
}
grub_free (assign);
-
- grub_snprintf (errnobuf, sizeof (errnobuf), "%d", grub_errno);
- grub_env_set ("?", errnobuf);
-
- return 0;
+ return grub_errno;
}
}
grub_free (args[i]);
grub_free (args);
- grub_snprintf (errnobuf, sizeof (errnobuf), "%d", ret);
- grub_env_set ("?", errnobuf);
-
return ret;
}
grub_err_t
grub_script_execute_cmdblock (struct grub_script_cmd *cmd)
{
+ int ret = 0;
struct grub_script_cmdblock *cmdblock = (struct grub_script_cmdblock *) cmd;
/* Loop over every command and execute it. */
for (cmd = cmdblock->cmdlist; cmd; cmd = cmd->next)
- grub_script_execute_cmd (cmd);
+ ret = grub_script_execute_cmd (cmd);
- return 0;
+ return ret;
}
/* Execute an if statement. */