Subject: A potential approach to making tests faster on Windows

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Fri, 30 Mar 2018 20:45:45 +0200

On Fri, Mar 30 2018, Johannes Schindelin wrote [expressing frustrations
about Windows test suite slowness]:

I've wondered for a while whether it wouldn't be a viable approach to
make something like an interpreter for our test suite to get around this
problem, i.e. much of it's very repetitive and just using a few shell
functions we've defined, what if we had C equivalents of those?

Duy had a WIP patch set a while ago to add C test suite support, but I
thought what if we turn that inside-out, and instead have a shell
interpreter that knows about the likes of test_cmp, and executes them
directly?

Here's proof of concept as a patch to the dash shell:

    u dash (debian/master=) $ git diff
    diff --git a/src/builtins.def.in b/src/builtins.def.in
    index 4441fe4..b214a17 100644
    --- a/src/builtins.def.in
    +++ b/src/builtins.def.in
    @@ -92,3 +92,4 @@ ulimitcmd     ulimit
     #endif
     testcmd                test [
     killcmd                -u kill
    +testcmpcmd     test_cmp
    diff --git a/src/jobs.c b/src/jobs.c
    index c2c2332..905563f 100644
    --- a/src/jobs.c
    +++ b/src/jobs.c
    @@ -1502,3 +1502,12 @@ getstatus(struct job *job) {
                    jobno(job), job->nprocs, status, retval));
            return retval;
     }
    +
    +#include <stdio.h>
    +int
    +testcmpcmd(argc, argv)
    +       int argc;
    +       char **argv;
    +{
    +       fprintf(stderr, "Got %d arguments\n", argc);
    +}

I just added that to jobs.c because it was easiest, then test_cmp
becomes a builtin:

    u dash (debian/master=) $ src/dash -c 'type test_cmp'
    test_cmp is a shell builtin
    u dash (debian/master=) $ src/dash -c 'echo foo && test_cmp 1 2 3'
    foo
    Got 4 arguments

I.e. it's really easy to add new built in commands to the dash shell
(and probably other shells, but dash is really small & fast).

We could carry some patch like that to dash, and also patch it so
test-lib.sh could know that that was our own custom shell, and we'd then
skip defining functions like test_cmp, and instead use that new builtin.

Similarly, it could then be linked to our own binaries, and the
test-tool would be a builtin that would appropriately dispatch, and we
could even eventually make "git" a shell builtin.

I don't have time or interest to work on this now, but thought it was
interesting to share. This assumes that something in shellscript like:

    while echo foo; do echo bar; done

Is no slower on Windows than *nix, since it's purely using built-ins, as
opposed to something that would shell out.