0

I have written a C code. I want to test it using the makefile as the code mainly revolves working around on command line arguments and returning an exit code with printf() writing the reason. return 0; //SUCCESS and return 1; //FALIURE

I used this article as a reference guide for my intended purpose.

Here is the structure for an idea.

MAKE = gcc
FILENAME = topcgpas.c
TARGET = topcgpas

compile:
    $(MAKE) $(FILENAME) -o $(TARGET)

run: compile
    ./$(TARGET) students.csv a.csv

testAll: compile test1 test2 test3 test4 test5 test6
    @echo "All done"

test1:
    @echo "TEST: Incorrect number of arguments"
    ./$(TARGET) 1 2 3

test2:
    @echo "TEST: Incorrect input/output filename"
    ./$(TARGET) no.csv output.csv

make testAll gives me

gcc topcgpas.c -o topcgpas
TEST: Incorrect number of arguments
./topcgpas 1 2 3
Usage ./topcgpas <sourcecsv> <outputcsv>
make: *** [makefile:16: test1] Error 1

However, to my understanding it should complete the execution for all tests.

vhmvd
  • 192
  • 3
  • 15
  • @EugeneSh. Yes, it partially answers my question but I want to get rid of `make: *** [makefile:16: test1] Error 1` from the output – vhmvd Apr 09 '21 at 16:40

1 Answers1

1

No. Make by default will exit on the first target that fails. If you want make to keep trying and run all the rules it can (it won't try to build any target that depends on a failed prerequisite of course) you can add the -k option.

See https://www.gnu.org/software/make/manual/html_node/Errors.html

It looks to me like you're trying to do negative testing. That means that you want your test to succeed if the operation fails, and to fail if the operation succeeds. In that case you don't want to ignore the error, you want to invert it. This should work:

test1:
         @echo "TEST: Incorrect number of arguments"
         if ./$(TARGET) 1 2 3; then false; fi
MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • How can I omit the lines like `make: [makefile:32: test5] Error 1 (ignored)`. – vhmvd Apr 09 '21 at 16:45
  • There is no way to remove that message, all you can do is change your recipe so make doesn't see a failure unless you want it to. – MadScientist Apr 09 '21 at 16:52