[Top][All Lists]

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

Re: Dependency injection and unit testing of M4 macros

From: tsuna
Subject: Re: Dependency injection and unit testing of M4 macros
Date: Wed, 10 Sep 2008 16:51:11 +0200

On Wed, Sep 10, 2008 at 2:33 PM, Eric Blake <address@hidden> wrote:
> According to tsuna on 9/10/2008 2:39 AM:
>> I tried to use m4_rename like so:
>> m4_rename([SOME_DEP], [SAVED_SOME_DEP])dnl <-- this is line 300
>> AC_DEFUN([SOME_DEP], [echo hooked cheap dep])
>> # my test with MY_MACOR here
>> m4_rename([SAVED_SOME_DEP], [SOME_DEP])
> Was this at the top level, or inside the definition of another macro?

top level

>  If at the top level, is SOME_DEP defined before this point?  Normally, you

Yes, in a different file that was m4_include'd beforehand.

> can AC_DEFUN a macro before its dependencies, so long as the dependencies
> are defined before the macro is expanded, but if you are trying m4_rename
> at the top level, then you don't have the luxury of a deferred definition
> of dependent macros.  If you were using m4_define instead of m4_defun,
> then I would suggest m4_pushdef/m4_popdef rather than m4_rename, but
> m4_pushdef doesn't play nicely with dependency tracking.

OK I understand that the dependencies and mechanisms behind AC_REQUIRE
are making this a bit more complex but I can't even properly inject
another definition for a macro that is simply called (such as the case
of _MY_HELPER_MACRO which is called from MY_MACRO).

>> AC_DEFUN == m4_defun, right?  And m4_defun does a m4_define, so what
>> am I doing wrong?
> But it also tracks dependency, and sets things up to define witness macros
> when SOME_DEP is expanded.  I'm not sure this will work for you, because
> once you've expanded your alternate SOME_DEP, I don't know how you would
> reset the witness machinery to think that SOME_DEP had not been used.
> You can always turn on m4 tracing to try and figure out what is going on.
>  For that matter, since you are trying to fake out dependencies to gain
> some speed, it may be worth looking into m4sugar, to figure out which
> undocumented witness macros to undefine to restore state (although I'm not
> sure m4sugar should be modified to add such a macro to its public API).
> But I'm afraid I won't be very effective at offering suggestions without a
> standalone example that I can try compiling, instead of just snippets.

Here is a full, standalone autoconfiscated package to reproduce what
I'm trying to do:

-------------------- begin --------------------
AC_INIT([example], [0.1])


# Initialize the test suite.


-------------------- end --------------------
-------------------- begin --------------------
ACLOCAL_AMFLAGS = -I build-aux

SUBDIRS = . tests
-------------------- end --------------------
-------------------- begin build-aux/mypkg.m4 --------------------
[echo some dep

[echo my helper macro

echo some code here
echo some more code here
-------------------- end build-aux/mypkg.m4 --------------------
-------------------- begin tests/ --------------------
TESTSUITE = $(srcdir)/testsuite
CLEANFILES = atconfig

check-local: atconfig $(TESTSUITE)

        test ! -f $(TESTSUITE) || $(SHELL) $(TESTSUITE) --clean
        rm -f -r autom4te.cache

AUTOTEST = $(AUTOM4TE) --language=autotest

$(TESTSUITE): $(srcdir)/
        $(AUTOTEST) -I '$(srcdir)' address@hidden -o address@hidden
        mv address@hidden $@

atconfig: $(top_builddir)/config.status
        cd $(top_builddir) && $(SHELL) ./config.status tests/$@
-------------------- end tests/ --------------------
-------------------- begin tests/ --------------------
m4_define([AT_PACKAGE_STRING], [whatever])

AT_BANNER([Heavy tests])

AT_SETUP([End ot end test of MY_MACRO])
dnl check that MY_MACRO worked...

AT_BANNER([Lightweight tests])

AT_SETUP([Smaller test of MY_MACRO])

m4_rename([SOME_DEP], [SAVED_SOME_DEP])

AC_DEFUN([SOME_DEP], [echo hooked cheap dep])
AC_DEFUN([_MY_HELPER_MACRO], [echo hooked cheap helper])

echo test begins
echo test ends

m4_rename([SAVED_SOME_DEP], [SOME_DEP])

-------------------- end tests/ --------------------

(alternatively you can use instead)

Benoit Sigoure aka Tsuna
EPITA Research and Development Laboratory

reply via email to

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