My directory currently looks like this
├── Makefile
├── run_tests (Unix executable)
└── src
└── vehicles
├── Wheels.java
└── Cars.java
└── RunProgram.java
tests
└── test1.txt
└── test2.txt
RunProgram.java is my main.
Looking online, I currently have a Makefile that looks like this:
JFLAGS = -g
JC = javac
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = \
src/vehicles/Wheels.java \
src/vehicles/Cars.java \
src/RunProgram.java
default: classes
classes: $(CLASSES:.java=.class)
clean:
$(RM) *.class
I have two main issues right now.
1. Cars.java throws an "error: cannot find symbol" for Wheels even though it compiles Wheels first (previously I had the order wrong, now it's correct).
2. I'm going to need to add a "test" to the Makefile eventually, which comes with its own problems. Essentially run_tests will put everything in the tests folder through System.in. However it has trouble running things in another directory, so I have to output the RunProgram.class to the root directory.
THIS IS HOW I RAN THE TESTS FROM THE COMMAND LINE WHEN THE ONLY PROGRAM IN THE PACKAGE STRUCTURE WAS RunProgram.java
javac -d ./ ./src/RunProgram.java
./run_tests "java RunProgram"
However, when I try running javac now I get errors that package imports don't exist. This is why I'm going with Makefile, as that's the ideal solution.
TL;DR I need a way to compile my program with Makefile and write a "make test" command that can properly call run_tests
I'm also willing to accept a solution that allows me to run javac from the command line and run the the tests from there, but Makefile is preferred
Best I could do to solve this was make a jar file and then do ./run_tests "java -jar RunProgram.jar"
Obviously not ideal but it worked.