[programs/robocopy.exe] How to do unit test correctly?

Weiwen Chen ofey206 at gmail.com
Sat Jun 26 14:02:23 CDT 2021


> I didn't find a program which has to deal with such complex parsing, and
the complexity to write a structure to parse all three kinds of flags seems
to be similar to implementing a dos-style `getopt`.

A finite automata may be a good and easy-to-do solution, if I want to do a
specific implementation ;)

Weiwen Chen <ofey206 at gmail.com> 于2021年6月27日周日 上午2:51写道:

> > Well, you could, but it may be easier to copy the structure from a
> different program, e.g. programs/ping/ping_main.c.
>
> I considered this choice at first, and I read some of the command line
> parsing patterns from other files. But robocopy has covered almost all
> kinds of dos-style command line flags:
> - flag with no argument, eg: /x
> - colon separated argument, eg: /x:10
> - space separated argument list, eg: /x arg1 arg2
>
> The three types are all needed by Waves Central or Scoop.
>
> I didn't find a program which has to deal with such complex parsing, and
> the complexity to write a structure to parse all three kinds of flags seems
> to be similar to implementing a dos-style `getopt`. Besides, `getopt` is
> something standard, and I can refer to lots of implementations. If a
> dos-style `getopt` is done, maybe it could help new programs or improve
> existing programs.
>
> I think I could do my test of `getopt` somewhere else, and copy tested
> code to the wine project. `getopt` is not hard/complex, and there are
> standard implementations which are proved to be right.
>
> Unittest of such a little program may be too cumbersome. ;)
>
> Weiwen
>
> Zebediah Figura (she/her) <zfigura at codeweavers.com> 于2021年6月26日周六
> 下午11:52写道:
>
>> Hello Weiwen,
>>
>> On 6/26/21 6:38 AM, Weiwen Chen wrote:
>> > Hi everyone:
>> > I'm Weiwen Chen from Fudan University and I'm working on adding
>> > `robocopy.exe` into wine. I stage my work on my github fork
>> > <https://github.com/ofey404/wine/tree/robocopy>.
>> >
>> > This program accepts complex command line arguments, so I'm trying to
>> > implement my own `getopt` function which accepts dos-style
>> flags(beginning
>> > with slash, like `/x`).
>>
>> Well, you could, but it may be easier to copy the structure from a
>> different program, e.g. programs/ping/ping_main.c.
>>
>> > The dummy code is under programs/robocopy
>> > <https://github.com/ofey404/wine/tree/robocopy/programs/robocopy>
>> > directory. And I want to add some unittest of `getopt_long()`, in
>> > robocopy/tests/getopt.c
>> > <
>> https://github.com/ofey404/wine/blob/fe4a71850b023eefadab5ce357ce4671c1fffc72/programs/robocopy/tests/getopt.c#L21
>> >.
>> > I try to import my source code of `getopt.c` relatively into unit test
>> > file, but I failed with error message like this:
>> >
>> > ../wine-git/programs/robocopy/tests/getopt.c:20: error: #include
>> directive
>> > with relative path not allowed
>> >
>> > How can I include my source file correctly into the test? Maybe I should
>> > configure something in the `configure` script, but I don't know how to
>> do
>> > it.
>> >
>> > I've read some of the builtin programs, but they seldom have a separate
>> > `test/` directory, and I don't find examples of unit tests.
>>
>> We don't really do unit tests of internal functions at all. Maybe
>> there's an argument for it, but I suspect in this case at least it's not
>> really necessary.
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-devel/attachments/20210627/7d532507/attachment.htm>


More information about the wine-devel mailing list