File size: 12,146 Bytes
a10b189 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | {-|
Module : Test.Verify.CITests
Description : Tests for CI integration and batch reporting
Copyright : (c) 2026 Ahmad Ali Parr
License : BSL-1.0
Tests covering:
- Batch verification from multiple files
- Aggregated reporting (JSON, CSV)
- Exit codes
- Code generation
- Deterministic batch reports
-}
module Test.Verify.CITests (tests) where
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (testCase, (@?=), Assertion)
import System.Exit (ExitCode(..))
import Assertica.Verify.CI
( BatchVerificationReport (..)
, generateBatchReport
, generateBatchJSON
, generateBatchCSV
, getExitCode
, generateBatchHumanReadable
)
import Assertica.Verify.Report
( VerificationReport (..)
, StageResult (..)
, Verdict (..)
, SourceLocation (..)
, ErrorDetail (..)
, ErrorCategory (..)
, mkStageResult
, mkReport
)
-- ============================================================================
-- CI INTEGRATION TESTS
-- ============================================================================
tests :: TestTree
tests = testGroup "Assertica.Verify.CI"
[ testGroup "Batch Report Generation"
[ testCase "empty batch report has zero files" $
testEmptyBatchReport
, testCase "batch report counts successful files" $
testBatchReportCountsSuccessful
, testCase "batch report counts failed files" $
testBatchReportCountsFailed
, testCase "batch report calculates pass rate" $
testBatchReportPassRate
, testCase "batch report calculates total duration" $
testBatchReportTotalDuration
]
, testGroup "Exit Codes"
[ testCase "all success returns ExitSuccess" $
testExitCodeSuccess
, testCase "one failure returns ExitFailure 1" $
testExitCodeOneFailure
, testCase "multiple failures return correct count" $
testExitCodeMultipleFailures
]
, testGroup "JSON Batch Export"
[ testCase "batch JSON contains summary" $
testBatchJSONContainsSummary
, testCase "batch JSON contains file count" $
testBatchJSONContainsFileCount
, testCase "batch JSON contains pass rate" $
testBatchJSONContainsPassRate
, testCase "batch JSON is well-formed" $
testBatchJSONWellFormed
, testCase "batch JSON is deterministic" $
testBatchJSONDeterministic
]
, testGroup "CSV Batch Export"
[ testCase "batch CSV contains header" $
testBatchCSVContainsHeader
, testCase "batch CSV has one row per file" $
testBatchCSVRowCount
, testCase "batch CSV contains summary" $
testBatchCSVContainsSummary
]
, testGroup "Human-Readable Batch Report"
[ testCase "batch text contains summary" $
testBatchTextContainsSummary
, testCase "batch text shows pass rate" $
testBatchTextShowsPassRate
]
, testGroup "Determinism"
[ testCase "same reports produce same batch JSON" $
testBatchJSONDeterminismExact
, testCase "same reports produce same batch CSV" $
testBatchCSVDeterminismExact
]
]
-- ============================================================================
-- BATCH REPORT GENERATION TESTS
-- ============================================================================
testEmptyBatchReport :: Assertion
testEmptyBatchReport = do
batchReport <- generateBatchReport []
bvrTotalFiles batchReport @?= 0
bvrSuccessful batchReport @?= 0
bvrFailed batchReport @?= 0
testBatchReportCountsSuccessful :: Assertion
testBatchReportCountsSuccessful = do
let stage = mkStageResult "Test" 10.0
report1 = mkReport "test1.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
report2 = mkReport "test2.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report1, report2]
bvrSuccessful batchReport @?= 2
testBatchReportCountsFailed :: Assertion
testBatchReportCountsFailed = do
let stage = mkStageResult "Test" 10.0
err = ErrorDetail SyntaxError "Error" Nothing Nothing Nothing
failStage = StageFailed "Test" 10.0 err
report1 = mkReport "test1.as" Nothing Nothing "2026-01-01T00:00:00Z" failStage stage stage stage stage
report2 = mkReport "test2.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report1, report2]
bvrFailed batchReport @?= 1
testBatchReportPassRate :: Assertion
testBatchReportPassRate = do
let stage = mkStageResult "Test" 10.0
report1 = mkReport "test1.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
report2 = mkReport "test2.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report1, report2]
bvrPassRate batchReport @?= 100.0
testBatchReportTotalDuration :: Assertion
testBatchReportTotalDuration = do
let stage1 = mkStageResult "Test" 10.0
stage2 = mkStageResult "Test" 10.0
stage3 = mkStageResult "Test" 10.0
stage4 = mkStageResult "Test" 10.0
stage5 = mkStageResult "Test" 10.0
report1 = mkReport "test1.as" Nothing Nothing "2026-01-01T00:00:00Z" stage1 stage2 stage3 stage4 stage5
report2 = mkReport "test2.as" Nothing Nothing "2026-01-01T00:00:00Z" stage1 stage2 stage3 stage4 stage5
batchReport <- generateBatchReport [report1, report2]
bvrTotalDuration batchReport @?= 100.0
-- ============================================================================
-- EXIT CODE TESTS
-- ============================================================================
testExitCodeSuccess :: Assertion
testExitCodeSuccess = do
let stage = mkStageResult "Test" 10.0
report = mkReport "test.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report]
getExitCode batchReport @?= ExitSuccess
testExitCodeOneFailure :: Assertion
testExitCodeOneFailure = do
let stage = mkStageResult "Test" 10.0
err = ErrorDetail SyntaxError "Error" Nothing Nothing Nothing
failStage = StageFailed "Test" 10.0 err
report = mkReport "test.as" Nothing Nothing "2026-01-01T00:00:00Z" failStage stage stage stage stage
batchReport <- generateBatchReport [report]
getExitCode batchReport @?= ExitFailure 1
testExitCodeMultipleFailures :: Assertion
testExitCodeMultipleFailures = do
let stage = mkStageResult "Test" 10.0
err = ErrorDetail SyntaxError "Error" Nothing Nothing Nothing
failStage = StageFailed "Test" 10.0 err
report1 = mkReport "test1.as" Nothing Nothing "2026-01-01T00:00:00Z" failStage stage stage stage stage
report2 = mkReport "test2.as" Nothing Nothing "2026-01-01T00:00:00Z" failStage stage stage stage stage
batchReport <- generateBatchReport [report1, report2]
getExitCode batchReport @?= ExitFailure 2
-- ============================================================================
-- JSON BATCH EXPORT TESTS
-- ============================================================================
testBatchJSONContainsSummary :: Assertion
testBatchJSONContainsSummary = do
let stage = mkStageResult "Test" 10.0
report = mkReport "test.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report]
let json = generateBatchJSON batchReport
("summary" `elem` lines json) @?= True
testBatchJSONContainsFileCount :: Assertion
testBatchJSONContainsFileCount = do
let stage = mkStageResult "Test" 10.0
report = mkReport "test.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report]
let json = generateBatchJSON batchReport
("totalFiles" `elem` concat (lines json)) @?= True
testBatchJSONContainsPassRate :: Assertion
testBatchJSONContainsPassRate = do
let stage = mkStageResult "Test" 10.0
report = mkReport "test.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report]
let json = generateBatchJSON batchReport
("passRate" `elem` concat (lines json)) @?= True
testBatchJSONWellFormed :: Assertion
testBatchJSONWellFormed = do
let stage = mkStageResult "Test" 10.0
report = mkReport "test.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report]
let json = generateBatchJSON batchReport
('{' `elem` json && '}' `elem` json) @?= True
testBatchJSONDeterministic :: Assertion
testBatchJSONDeterministic = do
let stage = mkStageResult "Test" 10.0
report = mkReport "test.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report]
let json1 = generateBatchJSON batchReport
json2 = generateBatchJSON batchReport
json1 @?= json2
testBatchJSONDeterminismExact :: Assertion
testBatchJSONDeterminismExact = do
let stage = mkStageResult "Test" 10.0
report = mkReport "test.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report]
generateBatchJSON batchReport @?= generateBatchJSON batchReport
-- ============================================================================
-- CSV BATCH EXPORT TESTS
-- ============================================================================
testBatchCSVContainsHeader :: Assertion
testBatchCSVContainsHeader = do
let stage = mkStageResult "Test" 10.0
report = mkReport "test.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report]
let csv = generateBatchCSV batchReport
("File,Module,Revision,Verdict,Duration" `elem` lines csv) @?= True
testBatchCSVRowCount :: Assertion
testBatchCSVRowCount = do
let stage = mkStageResult "Test" 10.0
report1 = mkReport "test1.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
report2 = mkReport "test2.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report1, report2]
let csv = generateBatchCSV batchReport
lineCount = length (lines csv)
-- Header + 2 data rows + summary comment + summary rows
(lineCount >= 3) @?= True
testBatchCSVContainsSummary :: Assertion
testBatchCSVContainsSummary = do
let stage = mkStageResult "Test" 10.0
report = mkReport "test.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report]
let csv = generateBatchCSV batchReport
("Summary" `elem` csv) @?= True
-- ============================================================================
-- HUMAN-READABLE BATCH REPORT TESTS
-- ============================================================================
testBatchTextContainsSummary :: Assertion
testBatchTextContainsSummary = do
let stage = mkStageResult "Test" 10.0
report = mkReport "test.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report]
let text = generateBatchHumanReadable batchReport
("BATCH VERIFICATION REPORT" `elem` lines text) @?= True
testBatchTextShowsPassRate :: Assertion
testBatchTextShowsPassRate = do
let stage = mkStageResult "Test" 10.0
report = mkReport "test.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report]
let text = generateBatchHumanReadable batchReport
("Pass Rate" `elem` concat (lines text)) @?= True
-- ============================================================================
-- DETERMINISM TESTS
-- ============================================================================
testBatchCSVDeterminismExact :: Assertion
testBatchCSVDeterminismExact = do
let stage = mkStageResult "Test" 10.0
report = mkReport "test.as" Nothing Nothing "2026-01-01T00:00:00Z" stage stage stage stage stage
batchReport <- generateBatchReport [report]
generateBatchCSV batchReport @?= generateBatchCSV batchReport
|