Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying test driver & makefile #100

Merged
merged 2 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ jobs:
- name: make - copy test into testing folder
run: make init_test

- name: make - test
run: make test
- name: make - test_silent
# Running silent (without progress check)
run: make test_silent

- name: cleaning afterworks
run: make clean
44 changes: 33 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
CXX := g++
CXXFLAGS := -Wall -static -static-libgcc -static-libstdc++ -std=c++17

# For compiling
SRC_DIR := src
OBJ_DIR := obj
SRC_FILES := $(wildcard $(SRC_DIR)/*.cpp)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRC_FILES))
EXECUTABLE_NAME := main

# For testing
TEST_DIR := tests
TEST_PAYLOAD := cd $(TEST_DIR) && pwd && bash test.sh

# For linting and format
LINT_PAYLOAD := find src/ -iname *.c -o -iname *.cpp -o -iname *.h | xargs clang-format --dry-run --Werror -style=file
FORMAT_PAYLOAD := find src/ -iname *.c -o -iname *.cpp -o -iname *.h | xargs clang-format -i -style=file

# For coverage
COVERAGE_FILENAME := coverage.info
COVERAGE_OUTPUT_DIR := coverage
COVERAGE_INIT_PAYLOAD := lcov --capture --directory obj --output-file=$(COVERAGE_FILENAME)
COVERAGE_EXTRACT_PAYLOAD := lcov --extract $(COVERAGE_FILENAME) '*.cpp' -o $(COVERAGE_FILENAME)
COVERAGE_GENERATE_REPORT_PAYLOAD := genhtml $(COVERAGE_FILENAME) --output-directory=$(COVERAGE_OUTPUT_DIR)

# For cleaning
REMOVAL := $(OBJ_DIR)/ $(EXECUTABLE_NAME) $(TEST_DIR)/$(EXECUTABLE_NAME) *.gcov $(COVERAGE_FILENAME) $(COVERAGE_OUTPUT_DIR)/


# Link object files to execution
main: $(OBJ_FILES)
$(EXECUTABLE_NAME): $(OBJ_FILES)
$(CXX) $(CXXFLAGS) -o $@ $^

# Compile to object files
Expand All @@ -19,35 +38,38 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp

# Clean directory for GitHub pushes
clean:
rm -rf $(OBJ_DIR) main $(TEST_DIR)/main
rm -rf *.gcov coverage.info coverage/
rm -rf $(REMOVAL)

# Initialise files for testing
init_test:
cp main $(TEST_DIR)/main
cp $(EXECUTABLE_NAME) $(TEST_DIR)/$(EXECUTABLE_NAME)

# Testing code
test:
cd $(TEST_DIR) && pwd && bash test.sh
$(TEST_PAYLOAD)

# Testing code on workflow
test_silent: TEST_PAYLOAD += --silent
test_silent:
$(TEST_PAYLOAD)

# Lint for code format
lint:
find src/ -iname *.c -o -iname *.cpp -o -iname *.h | xargs clang-format --dry-run --Werror -style=file
$(LINT_PAYLOAD)

# Format code
format:
find src/ -iname *.c -o -iname *.cpp -o -iname *.h | xargs clang-format -i -style=file
$(FORMAT_PAYLOAD)

# Run test coverage
gcov: CXXFLAGS += --coverage
gcov: $(OBJ_FILES)
$(CXX) $(CXXFLAGS) -o main $^
$(CXX) $(CXXFLAGS) -o $(EXECUTABLE_NAME) $^

# Generate human-readable coverage.
lcov:
lcov --capture --directory obj --output-file=coverage.info
lcov --extract coverage.info '*.cpp' -o coverage.info
$(COVERAGE_INIT_PAYLOAD) && $(COVERAGE_EXTRACT_PAYLOAD)

# Generate test coverage report
generate-coverage-report:
genhtml coverage.info --output-directory=coverage
$(COVERAGE_GENERATE_REPORT_PAYLOAD)
17 changes: 12 additions & 5 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
## @trhgquan - https://github.com/trhgquan
##

# Silent status - display status check if has this option.
silent=$1

# Colors
GREEN="\033[0;32m"
RED="\033[0;31m"
Expand Down Expand Up @@ -40,9 +43,11 @@ do
if [[ $(< output/$i.out) != "$check" ]]; then
# If failed, print the failed testcase (expected & runtime)

current_progress="${current_progress}${RED}✘${NC}"
if [[ $silent == "" ]]; then
current_progress="${current_progress}${RED}✘${NC}"

echo -ne "Testing: ${current_progress}${remain_progress} ($((${i} + 1))/${total_testcases})\r"
echo -ne "Testing: ${current_progress}${remain_progress} ($((${i} + 1))/${total_testcases})\r"
fi

echo -ne "\n"

Expand All @@ -62,10 +67,12 @@ do

else
# Else, print progress (with green ticks!)

current_progress="${current_progress}${GREEN}✔${NC}"
# Of course, print progress only when silent mode is not on.
if [[ $silent == "" ]]; then
current_progress="${current_progress}${GREEN}✔${NC}"

echo -ne "Testing: ${current_progress}${remain_progress} ($((${i} + 1))/${total_testcases})\r"
echo -ne "Testing: ${current_progress}${remain_progress} ($((${i} + 1))/${total_testcases})\r"
fi
fi
done

Expand Down