cons-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ctrl-C on Win32


From: Steven Knight
Subject: Re: Ctrl-C on Win32
Date: Mon, 23 Apr 2001 12:00:22 -0500 (CDT)

> So I think Cons does "too much" in it's signal handler.
> Maybe Cons could be changed to just set a global variable
> $main::ctrl_c, and then terminate "gracefully" at a later time in
> Cons "main-loop".

I agree.  This would be more robust.

> I the cases that Cons is waiting in a system-call (which is the most
> usual case) the exit code from "system" already indicates that
> something went wrong, but the check for $main::ctrl_c is needed in
> the other cases.
>
> I have tested my ideas with 5.6 and it seem to work as expected,
> but I don't know how to write a testcase for it (especially the
> timing-dependent part).

This is a fun one for building a test case...  Here's an outline of how
I'd do it:

You'll need the pid of the running Cons.  I think you can do this
portably by building a file with Command, and use a "[perl]" string
which just prints $$ to the file.  Another way would be to fork() and
then exec Cons, because the test would get the child pid directly, but I
don't think that's portable to Win32.  (Plus, the Test::Cmd::Cons module
doesn't support it; that would be a good enhancement...)

Build two files (A and C) any way you want.

Use Command to build a third file (B) by invoking a script that you
create in-line from the test case.  The script should build the target
file, but also sleep(), say for three seconds.  This will be when you'll
interrupt Cons (avoiding timing issues).

Use Depends to make sure that A is built first, then B, then C.

Run Cons in the background, either using fork() or by detaching it using
"&" on the command-line string.

Now have the test sleep the same number of seconds as the script it
invokes to build file B.  Then "kill(INT, $pid)" the running Cons, the
equivalent of sending it CTRL-C.

Then either examine the .consign file to see that file A's entry is
there, or run Cons again and check its output to see that it correctly
found file A's .consign entry and did *not* rebuild it, but that it did
build files B and C.

I did something similar for the test suite for the cons-test script
itself.  (Yes, it has tests; they're much less extensive...)  I'll
attach that in a separate message so as not to clog the list.

        --SK




reply via email to

[Prev in Thread] Current Thread [Next in Thread]