@@ -342,6 +342,69 @@ func TestDiagnostic(t *testing.T) {
342342[red]│[reset]
343343[red]│[reset] LHS not equal to RHS
344344[red]╵[reset]
345+ ` ,
346+ },
347+ "error originating from failed wrapped test assertion by function" : {
348+ & hcl.Diagnostic {
349+ Severity : hcl .DiagError ,
350+ Summary : "Test assertion failed" ,
351+ Detail : "Example crash" ,
352+ Subject : & hcl.Range {
353+ Filename : "test.tf" ,
354+ Start : hcl.Pos {Line : 1 , Column : 6 , Byte : 5 },
355+ End : hcl.Pos {Line : 1 , Column : 12 , Byte : 11 },
356+ },
357+ Expression : & hclsyntax.FunctionCallExpr {
358+ Name : "tobool" ,
359+ Args : []hclsyntax.Expression {
360+ & hclsyntax.BinaryOpExpr {
361+ Op : hclsyntax .OpEqual ,
362+ LHS : & hclsyntax.LiteralValueExpr {
363+ Val : cty .ObjectVal (map [string ]cty.Value {
364+ "inner" : cty .StringVal ("str1" ),
365+ "extra" : cty .StringVal ("str2" ),
366+ }),
367+ },
368+ RHS : & hclsyntax.LiteralValueExpr {
369+ Val : cty .ObjectVal (map [string ]cty.Value {
370+ "inner" : cty .StringVal ("str11" ),
371+ "extra" : cty .StringVal ("str21" ),
372+ }),
373+ },
374+ SrcRange : hcl.Range {
375+ Filename : "test.tf" ,
376+ Start : hcl.Pos {Line : 1 , Column : 6 , Byte : 5 },
377+ End : hcl.Pos {Line : 1 , Column : 12 , Byte : 11 },
378+ },
379+ },
380+ },
381+ },
382+ EvalContext : & hcl.EvalContext {
383+ Variables : map [string ]cty.Value {},
384+ Functions : map [string ]function.Function {
385+ "tobool" : function .New (& function.Spec {
386+ Params : []function.Parameter {
387+ {
388+ Name : "param_0" ,
389+ Type : cty .String ,
390+ },
391+ },
392+ }),
393+ },
394+ },
395+ // This is simulating what the test assertion expression
396+ // type would generate on evaluation, by implementing the
397+ // same interface it uses.
398+ Extra : diagnosticCausedByTestFailure {true },
399+ },
400+ `[red]╷[reset]
401+ [red]│[reset] [bold][red]Error: [reset][bold]Test assertion failed[reset]
402+ [red]│[reset]
403+ [red]│[reset] on test.tf line 1:
404+ [red]│[reset] 1: test [underline]source[reset] code
405+ [red]│[reset]
406+ [red]│[reset] Example crash
407+ [red]╵[reset]
345408` ,
346409 },
347410 }
0 commit comments