|
| 1 | +version: '3' |
| 2 | + |
| 3 | +vars: |
| 4 | + TEST_RESULTS_DIR: testresults |
| 5 | + REPORTS_DIR: reports |
| 6 | + COVERAGE_FILE: "{{.TEST_RESULTS_DIR}}/coverage.cobertura.xml" |
| 7 | + UNIT_TEST_PROJECT: tests/Valkey.Glide.UnitTests/Valkey.Glide.UnitTests.csproj |
| 8 | + INTEGRATION_TEST_PROJECT: tests/Valkey.Glide.IntegrationTests/Valkey.Glide.IntegrationTests.csproj |
| 9 | + |
| 10 | +tasks: |
| 11 | + clean: |
| 12 | + desc: Clean test results and reports directories |
| 13 | + cmds: |
| 14 | + - rm -rf {{.TEST_RESULTS_DIR}} |
| 15 | + - rm -rf {{.REPORTS_DIR}} |
| 16 | + - mkdir -p {{.TEST_RESULTS_DIR}} |
| 17 | + - mkdir -p {{.REPORTS_DIR}} |
| 18 | + |
| 19 | + install-tools: |
| 20 | + desc: Install required tools for coverage reporting |
| 21 | + cmds: |
| 22 | + - dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.4.12 |
| 23 | + status: |
| 24 | + - which reportgenerator |
| 25 | + |
| 26 | + test:unit: |
| 27 | + desc: Run unit tests only |
| 28 | + deps: [clean] |
| 29 | + cmds: |
| 30 | + - dotnet test {{.UNIT_TEST_PROJECT}} --configuration Release --no-build --verbosity normal |
| 31 | + |
| 32 | + test:integration: |
| 33 | + desc: Run integration tests only |
| 34 | + deps: [clean] |
| 35 | + cmds: |
| 36 | + - dotnet test {{.INTEGRATION_TEST_PROJECT}} --configuration Release --no-build --verbosity normal |
| 37 | + |
| 38 | + test:coverage:unit: |
| 39 | + desc: Run unit tests with coverage collection |
| 40 | + deps: [clean] |
| 41 | + cmds: |
| 42 | + - dotnet test {{.UNIT_TEST_PROJECT}} |
| 43 | + --configuration Release |
| 44 | + --collect:"XPlat Code Coverage" |
| 45 | + --results-directory {{.TEST_RESULTS_DIR}} |
| 46 | + --logger trx |
| 47 | + --logger "console;verbosity=detailed" |
| 48 | + -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura |
| 49 | + |
| 50 | + test:coverage:integration: |
| 51 | + desc: Run integration tests with coverage collection |
| 52 | + deps: [clean] |
| 53 | + cmds: |
| 54 | + - dotnet test {{.INTEGRATION_TEST_PROJECT}} |
| 55 | + --configuration Release |
| 56 | + --collect:"XPlat Code Coverage" |
| 57 | + --results-directory {{.TEST_RESULTS_DIR}} |
| 58 | + --logger trx |
| 59 | + --logger "console;verbosity=detailed" |
| 60 | + -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura |
| 61 | + |
| 62 | + test:coverage:all: |
| 63 | + desc: Run all tests with coverage collection |
| 64 | + deps: [clean] |
| 65 | + cmds: |
| 66 | + - dotnet test |
| 67 | + --configuration Release |
| 68 | + --collect:"XPlat Code Coverage" |
| 69 | + --results-directory {{.TEST_RESULTS_DIR}} |
| 70 | + --logger trx |
| 71 | + --logger "console;verbosity=detailed" |
| 72 | + -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura |
| 73 | + |
| 74 | + coverage:merge: |
| 75 | + desc: Merge coverage files if multiple exist |
| 76 | + cmds: |
| 77 | + - | |
| 78 | + COVERAGE_FILES=$(find {{.TEST_RESULTS_DIR}} -name "coverage.cobertura.xml" -type f) |
| 79 | + if [ $(echo "$COVERAGE_FILES" | wc -l) -gt 1 ]; then |
| 80 | + echo "Multiple coverage files found, merging..." |
| 81 | + reportgenerator \ |
| 82 | + -reports:"{{.TEST_RESULTS_DIR}}/**/coverage.cobertura.xml" \ |
| 83 | + -targetdir:{{.TEST_RESULTS_DIR}} \ |
| 84 | + -reporttypes:Cobertura \ |
| 85 | + -assemblyfilters:"+Valkey.Glide*" |
| 86 | + mv {{.TEST_RESULTS_DIR}}/Cobertura.xml {{.COVERAGE_FILE}} |
| 87 | + else |
| 88 | + echo "Single coverage file found, copying..." |
| 89 | + cp $(echo "$COVERAGE_FILES" | head -1) {{.COVERAGE_FILE}} |
| 90 | + fi |
| 91 | +
|
| 92 | + coverage:report: |
| 93 | + desc: Generate HTML coverage report from collected data |
| 94 | + deps: [install-tools, coverage:merge] |
| 95 | + cmds: |
| 96 | + - reportgenerator |
| 97 | + -reports:{{.COVERAGE_FILE}} |
| 98 | + -targetdir:{{.REPORTS_DIR}} |
| 99 | + -reporttypes:"Html;JsonSummary" |
| 100 | + -assemblyfilters:"+Valkey.Glide*" |
| 101 | + -classfilters:"-*.Tests*" |
| 102 | + - echo "Coverage report generated in {{.REPORTS_DIR}}/index.html" |
| 103 | + |
| 104 | + coverage:summary: |
| 105 | + desc: Display coverage summary from the report |
| 106 | + cmds: |
| 107 | + - | |
| 108 | + if [ -f "{{.REPORTS_DIR}}/Summary.json" ]; then |
| 109 | + echo "=== Coverage Summary ===" |
| 110 | + LINE_COVERAGE=$(cat {{.REPORTS_DIR}}/Summary.json | jq -r '.summary.linecoverage') |
| 111 | + BRANCH_COVERAGE=$(cat {{.REPORTS_DIR}}/Summary.json | jq -r '.summary.branchcoverage') |
| 112 | + echo "Line Coverage: ${LINE_COVERAGE}%" |
| 113 | + echo "Branch Coverage: ${BRANCH_COVERAGE}%" |
| 114 | + else |
| 115 | + echo "No coverage summary found. Run 'task coverage:report' first." |
| 116 | + fi |
| 117 | +
|
| 118 | + coverage: |
| 119 | + desc: Run all tests with coverage and generate HTML report |
| 120 | + cmds: |
| 121 | + - task: test:coverage:all |
| 122 | + - task: coverage:report |
| 123 | + - task: coverage:summary |
| 124 | + |
| 125 | + coverage:unit: |
| 126 | + desc: Run unit tests with coverage and generate HTML report |
| 127 | + cmds: |
| 128 | + - task: test:coverage:unit |
| 129 | + - task: coverage:report |
| 130 | + - task: coverage:summary |
| 131 | + |
| 132 | + coverage:integration: |
| 133 | + desc: Run integration tests with coverage and generate HTML report |
| 134 | + cmds: |
| 135 | + - task: test:coverage:integration |
| 136 | + - task: coverage:report |
| 137 | + - task: coverage:summary |
| 138 | + |
| 139 | + build: |
| 140 | + desc: Build the solution |
| 141 | + cmds: |
| 142 | + - dotnet build --configuration Release |
| 143 | + |
| 144 | + test: |
| 145 | + desc: Build and run all tests |
| 146 | + deps: [build] |
| 147 | + cmds: |
| 148 | + - task: test:coverage:all |
| 149 | + |
| 150 | + default: |
| 151 | + desc: Default task - build and run coverage |
| 152 | + cmds: |
| 153 | + - task: build |
| 154 | + - task: coverage |
0 commit comments