vsc 的Makefile怎么写urg覆盖率收集
时间: 2024-09-06 11:02:05 浏览: 39
在Visual Studio Code (VSC) 中,想要编写一个Makefile来收集测试覆盖率,通常会涉及到使用特定的工具,比如CMake、gcov或lcov配合CTest等。以下是创建一个基本Makefile示例,用于C++项目并利用gcov收集覆盖率:
```makefile
# Makefile for C++ project with coverage reporting using gcov
CC = gcc
CXX = g++
ifeq ($(shell uname), Darwin)
# For macOS, use llvm-cov instead of gcov
COVERAGE_TOOLS = llvm-cov gcov-8
else
COVERAGE_TOOLS = gcov
endif
# Build target
all: my_program
# Compile without coverage report
clean:
rm -f *.o my_program core*
# Compile with coverage report
coverage: COVERAGE_FLAGS = -O0 -ftest-coverage
coverage: my_program
$(COVERAGE_TOOLS)/gcov-llvm report -show-covered-blocks $(my_program)
# Run tests and generate coverage report
test_coverage:
cmake --build . --target test COVERAGE_FLAGS=-DCMAKE_CXX_FLAGS=$(COVERAGE_FLAGS)
@echo "Coverage report generated. Open `lcov.info` file to view it."
# Generate lcov.info from the build directory
gen_lcov:
cmake --build . --target gen_coverage_report
genhtml lcov.info -o htmlcov
# Clean up after coverage generation
clean_coverage:
rm -rf htmlcov lcov.info .coverage
# Default target is to build the program
my_program: %.o %.cpp
$(CXX) $^ -o $@
%.o: %.cpp
$(CC) $(COVERAGE_FLAGS) -c $<
.PHONY: clean coverage test_coverage gen_lcov clean_coverage all
#
阅读全文