Re: [LTP] [PATCH v3 4/4] testcaes/lib: Add shell loader

Cyril Hrubis
2024-09-16T10:06:22Z

Hi!
> > +static void extract_metadata(void)
> > +{
> > + FILE *f;
> > + char line[4096];
> > + char path[4096];
> > + enum parser_state state = PAR_NONE;
> > +
> > + if (tst_get_path(shell_filename, path, sizeof(path)) == -1)
> > + tst_brk(TBROK, "Failed to find %s in $PATH", shell_filename);
> > +
> > + f = SAFE_FOPEN(path, "r");
> > +
> > + while (fgets(line, sizeof(line), f)) {
> > + switch (state) {
> > + case PAR_NONE:
> > + if (!strcmp(line, "# ---\n"))
> What if user defines "#---" or "#   ---" ? IMHO it would be better to
> parse it following shell comments standards. In particular, "^#\s+---"
> using a *scan function.

If user sets the line any differently the test will end up with pretty
clear error message that metadata are missing, so I do not see this as
an issue.

> > + state = PAR_ESC;
> > + break;
> > + case PAR_ESC:
> > + if (!strcmp(line, "# env\n"))
> Same apply here and to the others.

Same here as well.

--
Cyril Hrubis
chrubis@suse.cz