Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #68161

Re: Use m4 and make to compose C programs

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: Use m4 and make to compose C programs
Date 2015-08-24 11:15 +1200
Message-ID <d3v2ghF3onsU1@mid.individual.net> (permalink)
References <ff7f0b6d-56e9-47a7-898f-b5fec727fc70@googlegroups.com> <d3qhhaFed1gU1@mid.individual.net> <9a4284c9-5108-48aa-8ee9-5664cae36f96@googlegroups.com> <d3qm98Fed1gU2@mid.individual.net> <ebda4134-87bd-425d-8252-4c43e57f268a@googlegroups.com>

Show all headers | View raw


luser droog wrote:
> On Saturday, August 22, 2015 at 2:22:27 AM UTC-5, Ian Collins wrote:
>> luser droog wrote:
>>> On Saturday, August 22, 2015 at 1:01:24 AM UTC-5, Ian Collins wrote:
>>>>
>>>> I'll snip here and ask the obvious question: why can't you just unit
>>>> test the code as is?
>>>
>>> I'm afraid I don't understand the question. How do you
>>> "unit test the code as is"?
>>
>> The code has nothing conditional or test specific in it.  What is built
>> for production is what is tested.
>
> With respect, this sounds to me more like a prejudice than a conclusion.
> My source files are organized into two sections.
>
> ....
> //module code
> ....
>
> #ifdef TESTMODULE
> ....
> //unit tests
> ....
> int main(){
>      // call unit tests
> }
> #endif
>
> I consider it a "partitioned file". It contains an "embedded resource".
> The module code is not contaminated thereby (that I can see from my POV).

I'd need to see a real example, but the normal practice with unit 
testing is to keep the source under test and the tests in separate 
source files.

Some unit test frameworks (CxxTest is one example) generate their main() 
by paring the tests and generating code.  Others use macros to build 
their test suites.

>>>> Everything I write has unit tests (I use TDD) and I never have anything
>>>> conditionally compiled.
>>>
>>> I imagine the testing code has to be separated into the "test" file.
>>
>> Test, in my case each logical module has its own test set of tests,
>> everything outside of that module is mocked.
>
> This sentence also describes my implementation, excepted that I haven't
> needed to mock anything yet.

Take so time to look as some of the unit test frameworks out there and 
you will see a common pattern.  This hasn't happened by chance, they end 
up that way in order to implement all of the features users want.  Look 
at both C and C++ frameworks, both can be used to unit test C code.

>>> I've also wanted to do something with m4 for a while. Here finally
>>> was something cpp couldn't do.
>>
>> Maybe, but is the cost (in hard to read code) worth the benefit?
>
> Is it really so hard to read? It's as direct and clear as I am (so far)
> able to make it.

Introducing an unfamiliar macro processing language will inevitably make 
it harder for programmers to read.  It also introduces a dependency on 
m4.  Is there windows m4 port?  Some existing frameworks use a scripting 
(the ones I've used use Python) for code generation, but the users 
doesn't see the code.

-- 
Ian Collins

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Use m4 and make to compose C programs luser droog <luser.droog@gmail.com> - 2015-08-21 22:53 -0700
  Re: Use m4 and make to compose C programs Ian Collins <ian-news@hotmail.com> - 2015-08-22 18:01 +1200
    Re: Use m4 and make to compose C programs luser droog <luser.droog@gmail.com> - 2015-08-21 23:43 -0700
      Re: Use m4 and make to compose C programs Ian Collins <ian-news@hotmail.com> - 2015-08-22 19:22 +1200
        Re: Use m4 and make to compose C programs luser droog <luser.droog@gmail.com> - 2015-08-23 13:13 -0700
          Re: Use m4 and make to compose C programs Ian Collins <ian-news@hotmail.com> - 2015-08-24 11:15 +1200
            Re: Use m4 and make to compose C programs Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-08-23 16:52 -0700
              Re: Use m4 and make to compose C programs Richard Damon <Richard@Damon-Family.org> - 2015-08-23 21:27 -0400
                Re: Use m4 and make to compose C programs Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-08-24 00:43 -0700
                Re: Use m4 and make to compose C programs <william@wilbur.25thandClement.com> - 2015-08-27 12:20 -0700
            Re: Use m4 and make to compose C programs luser droog <luser.droog@gmail.com> - 2015-08-26 23:22 -0700
              Re: Use m4 and make to compose C programs luser droog <luser.droog@gmail.com> - 2015-08-26 23:40 -0700

csiph-web