| 536 | } |
| 537 | |
| 538 | func TestFailErrors(t *testing.T) { |
| 539 | vals := common.Values{"Values": map[string]any{}} |
| 540 | |
| 541 | failtpl := `All your base are belong to us{{ fail "This is an error" }}` |
| 542 | tplsFailed := map[string]renderable{ |
| 543 | "failtpl": {tpl: failtpl, vals: vals}, |
| 544 | } |
| 545 | _, err := new(Engine).render(tplsFailed) |
| 546 | if err == nil { |
| 547 | t.Fatalf("Expected failures while rendering: %s", err) |
| 548 | } |
| 549 | expected := `execution error at (failtpl:1:33): This is an error` |
| 550 | if err.Error() != expected { |
| 551 | t.Errorf("Expected '%s', got %q", expected, err.Error()) |
| 552 | } |
| 553 | |
| 554 | var e Engine |
| 555 | e.LintMode = true |
| 556 | out, err := e.render(tplsFailed) |
| 557 | if err != nil { |
| 558 | t.Fatal(err) |
| 559 | } |
| 560 | |
| 561 | expectStr := "All your base are belong to us" |
| 562 | if gotStr := out["failtpl"]; gotStr != expectStr { |
| 563 | t.Errorf("Expected %q, got %q (%v)", expectStr, gotStr, out) |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | func TestAllTemplates(t *testing.T) { |
| 568 | modTime := time.Now() |