Skip to content

配置文件

Anvil 使用 YAML 格式的 .anvil 配置文件。

配置文件查找优先级

优先级位置说明
1(最高)命令行 --config命令行指定的配置文件
2.anvil项目目录(当前工作目录)
3~/.anvil用户主目录
4(最低)内置默认值无配置文件时使用

完整配置示例

yaml
# 编译器设置
compiler: gcc
compiler_flags:
  - -Wno-attributes    # 必须:抑制 anvil 属性警告
  - -Wall
  - -Wextra

# 目录设置
test_dir: tests
build_dir: build

# 测试执行设置
default_timeout: 30s

# 日志文件设置
compile_log: anvil-compile.log
test_log: anvil-test.log

# 输出设置
junit_file: ""
no_clean: false
no_check: false

# Include 路径设置(用于查找 anvil/mock.h)
anvil_include_paths:
  - include
  - ../include
  - /usr/local/include

# 代码覆盖率设置
coverage:
  enabled: false
  format: lcov           # gcov, lcov, html, cobertura
  output_dir: coverage
  exclude_patterns:
    - "*/tests/*"
    - "*/mocks/*"

配置项详解

编译器设置

配置项类型默认值说明
compilerstringgccC 编译器路径或名称
compiler_flagsstring[]["-Wno-attributes"]编译器标志列表

重要

-Wno-attributes 是必需的,用于抑制 Anvil 自定义属性的警告。

目录设置

配置项类型默认值说明
test_dirstringtests测试源文件目录
build_dirstringbuild编译产物目录(.o 文件)

执行设置

配置项类型默认值说明
default_timeoutduration30s单个测试的超时时间

支持的时间格式:30s, 500ms, 1m, 2m30s

日志设置

配置项类型默认值说明
compile_logstringanvil-compile.log编译日志路径
test_logstringanvil-test.log测试日志路径

输出设置

配置项类型默认值说明
junit_filestring""JUnit XML 报告路径
no_cleanboolfalse保留生成文件
no_checkboolfalse跳过构建目录验证

覆盖率设置

配置项类型默认值说明
coverage.enabledboolfalse启用覆盖率收集
coverage.formatstringlcov输出格式
coverage.output_dirstringcoverage输出目录
coverage.exclude_patternsstring[][]排除模式

场景配置示例

CI/CD 环境

yaml
compiler: gcc
compiler_flags:
  - -Wno-attributes
  - -Wall
  - -Werror          # 将警告视为错误

test_dir: tests
build_dir: build
default_timeout: 30s

compile_log: ci-logs/compile.log
test_log: ci-logs/test.log

junit_file: ci-reports/test-results.xml
no_clean: false
no_check: false

本地开发环境

yaml
compiler: gcc
compiler_flags:
  - -Wno-attributes
  - -g               # 调试信息
  - -O0              # 禁用优化

test_dir: tests
build_dir: build
default_timeout: 1m   # 较长超时便于调试

no_clean: true        # 保留生成文件便于调试

嵌入式项目

yaml
compiler: arm-none-eabi-gcc
compiler_flags:
  - -Wno-attributes
  - -mcpu=cortex-m4
  - -mthumb
  - -Os

test_dir: tests/host
build_dir: build/host
default_timeout: 10s

anvil_include_paths:
  - include
  - hal/include

启用覆盖率

yaml
compiler: gcc
compiler_flags:
  - -Wno-attributes
  - -fprofile-arcs
  - -ftest-coverage

coverage:
  enabled: true
  format: html
  output_dir: coverage
  exclude_patterns:
    - "*/tests/*"
    - "*/mocks/*"
    - "*/anvil-mocks/*"

本页面内容遵循 Luna 软件源代码授权条款 (LSLA) 发布