File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 1
1
# Compiler and flags
2
2
CXX := g++
3
- CXXFLAGS := -std=c++17 -Iinclude -Wall -Wextra -Werror
3
+ CXXFLAGS := -std=c++17 -Iinclude -I/usr/include/gtest -Wall -Wextra -Werror
4
+ GTEST_DIR := /usr/include/gtest
5
+ GTEST_LIB_DIR := /usr/lib/x86_64-linux-gnu
4
6
5
7
# Directories
6
8
SRC_DIR := src
7
9
INCLUDE_DIR := include
8
10
BUILD_DIR := build
9
11
OUTPUT_DIR := output
12
+ TEST_DIR := test
10
13
11
14
# Source and object files
12
15
SRCS := $(wildcard $(SRC_DIR ) /* .cpp)
13
16
OBJS := $(patsubst $(SRC_DIR ) /% .cpp, $(BUILD_DIR ) /% .o, $(SRCS ) )
14
17
18
+ # Object files excluding the main program
19
+ TEST_OBJS := $(filter-out $(BUILD_DIR ) /mian.o, $(OBJS ) )
20
+
15
21
# Target executable
16
22
TARGET := scanner
17
23
@@ -42,5 +48,18 @@ run: $(TARGET)
42
48
./$(TARGET ) examples/example1.txt $(OUTPUT_DIR ) /output.txt
43
49
cat $(OUTPUT_DIR ) /output.txt
44
50
45
- .PHONY : all clean run
51
+ # Build and run a specific test
52
+ test : $(TEST_OBJS ) | $(BUILD_DIR )
53
+ @echo " TEST_FILE is $( TEST_FILE) "
54
+ @if [ -z " $( TEST_FILE) " ]; then \
55
+ echo " Error: Please specify a test file using TEST_FILE=<test_file>" ; \
56
+ echo " Example: make test TEST_FILE=token_test" ; \
57
+ exit 1; \
58
+ else \
59
+ echo " Compiling $( TEST_DIR) /$( TEST_FILE) .cpp" ; \
60
+ $(CXX ) $(CXXFLAGS ) -I$(GTEST_DIR ) -L$(GTEST_LIB_DIR ) \
61
+ $(TEST_DIR ) /$(TEST_FILE ) .cpp $(TEST_OBJS ) -lgtest -lgtest_main -pthread \
62
+ -o $(BUILD_DIR ) /$(TEST_FILE ) _test && ./$(BUILD_DIR ) /$(TEST_FILE ) _test; \
63
+ fi
46
64
65
+ .PHONY : all clean run test
You can’t perform that action at this time.
0 commit comments