Feeding multiple test#.txt files using make. Some files require arguments. C++/VSCode/Ubuntu

26 Views Asked by At

I'm a student of computer science. I'm not here to get anyone to do my homework for me, only to ask for advice on how to polish it up, since my project is done. It's done early, so I'm taking some time to see what else is possible. This thing I'm asking is not a required part of the assignment.

It's a lexical analyzer and parser, building toward the ultimate goal of a compiler for a made-up language. For this iteration of the linked projects, there are 30 .txt files that must be fed to it, like so:

./compile < test/test1.txt

I added to the make file a recipe 'test' which iterates through a list of the applicable files and feeds them to the analyzer.

A handful of the functions under test require arguments, like so:

./compile < test/test11.txt 10.5 8

What I've done thus far is list every file as a variable at the top of the file as part of TESTING_P3:

TESTING_P3 := test/test1.txt
test/test11.txt 10.5 8
... ... and so on

My question is, does there exist a way to detect when a file is meant to have arguments passed to it, and feed those arguments to the function before moving on? Some require one, two, or three arguments of varying types (character, real, integer). Either my google skills are not strong, or no one's done this, maybe because it's not supposed to be done in a make file. If that's the case, maybe I've dead-ended for that reason.

This code in the makefile--

test: compile for file in $(TESTING_P3); do
printf "\nRunning test file\n%s\n" "$$file";
./compile < "$$file";
done

  • works great for just plowing through, but of course those tests result in 'missing parameter' errors from the program when I try weaving the arguments into the process.

Everything else I've tried (using test11 as an example) regards 10.5 and 8 as the next files to open, which of course results in a 'no such file exists' error. It doesn't stop going through the rest of the test files, at least. Thanks for your time.

1

There are 1 best solutions below

0
MadScientist On

As best as I can understand you seem to be looking for some sort of two-dimensional array (list of lists type thing) in make variables.

No such feature exists.

One simple way to do this is to combine your command and arguments into a single word by adding delimiters, then taking them out again when you run the command. Here's an example:

TESTING_P3 := test/test1.txt \
              test/test11.txt-10.5-8

test: $(TESTING_P3)

$(TESTING_P3): compile
         @printf "\nRunning test file\n%s\n" '$(subst -, ,$@)'
         ./$< $(wordlist 2,100,$(subst -, ,$@)) < '$(word 1,$(subst -, ,$@))'

See the GNU Make manual discussion of text functions for more details.