5
5
"encoding/json"
6
6
"errors"
7
7
"fmt"
8
- "io/ioutil "
8
+ "io"
9
9
"os"
10
10
"path/filepath"
11
11
"regexp"
@@ -100,7 +100,7 @@ func init() {
100
100
pongo2 .DefaultSet .BanFilter ("banned_filter" )
101
101
pongo2 .DefaultSet .BanTag ("banned_tag" )
102
102
103
- f , err := ioutil . TempFile (os .TempDir (), "pongo2_" )
103
+ f , err := os . CreateTemp (os .TempDir (), "pongo2_" )
104
104
if err != nil {
105
105
panic (fmt .Sprintf ("cannot write to %s" , os .TempDir ()))
106
106
}
@@ -382,15 +382,15 @@ func TestTemplates(t *testing.T) {
382
382
}
383
383
384
384
// Read options from file
385
- optsStr , _ := ioutil .ReadFile (fmt .Sprintf ("%s.options" , match ))
385
+ optsStr , _ := os .ReadFile (fmt .Sprintf ("%s.options" , match ))
386
386
trimBlocks := strings .Contains (string (optsStr ), "TrimBlocks=true" )
387
387
lStripBlocks := strings .Contains (string (optsStr ), "LStripBlocks=true" )
388
388
389
389
tpl .Options .TrimBlocks = trimBlocks
390
390
tpl .Options .LStripBlocks = lStripBlocks
391
391
392
392
testFilename := fmt .Sprintf ("%s.out" , match )
393
- testOut , rerr := ioutil .ReadFile (testFilename )
393
+ testOut , rerr := os .ReadFile (testFilename )
394
394
if rerr != nil {
395
395
t .Fatalf ("Error on ReadFile('%s'): %s" , testFilename , rerr .Error ())
396
396
}
@@ -402,7 +402,7 @@ func TestTemplates(t *testing.T) {
402
402
if ! bytes .Equal (testOut , tplOut ) {
403
403
t .Logf ("Template (rendered) '%s': '%s'" , match , tplOut )
404
404
errFilename := filepath .Base (fmt .Sprintf ("%s.error" , match ))
405
- err := ioutil .WriteFile (errFilename , []byte (tplOut ), 0o600 )
405
+ err := os .WriteFile (errFilename , []byte (tplOut ), 0o600 )
406
406
if err != nil {
407
407
t .Fatalf (err .Error ())
408
408
}
@@ -430,7 +430,7 @@ func TestBlockTemplates(t *testing.T) {
430
430
}
431
431
432
432
testFilename := fmt .Sprintf ("%s.out" , match )
433
- testOut , rerr := ioutil .ReadFile (testFilename )
433
+ testOut , rerr := os .ReadFile (testFilename )
434
434
if rerr != nil {
435
435
t .Fatalf ("Error on ReadFile('%s'): %s" , testFilename , rerr .Error ())
436
436
}
@@ -450,7 +450,7 @@ func TestBlockTemplates(t *testing.T) {
450
450
if testString != joinedString {
451
451
t .Logf ("BlockTemplate (rendered) '%s': '%s'" , match , tpl_out ["content" ])
452
452
errFilename := filepath .Base (fmt .Sprintf ("%s.error" , match ))
453
- err := ioutil .WriteFile (errFilename , []byte (joinedString ), 0o600 )
453
+ err := os .WriteFile (errFilename , []byte (joinedString ), 0o600 )
454
454
if err != nil {
455
455
t .Fatalf (err .Error ())
456
456
}
@@ -489,14 +489,14 @@ func TestExecutionErrors(t *testing.T) {
489
489
}
490
490
for idx , match := range matches {
491
491
t .Run (fmt .Sprintf ("%03d-%s" , idx + 1 , match ), func (t * testing.T ) {
492
- testData , err := ioutil .ReadFile (match )
492
+ testData , err := os .ReadFile (match )
493
493
if err != nil {
494
494
t .Fatalf ("could not read file '%v': %v" , match , err )
495
495
}
496
496
tests := strings .Split (string (testData ), "\n " )
497
497
498
498
checkFilename := fmt .Sprintf ("%s.out" , match )
499
- checkData , err := ioutil .ReadFile (checkFilename )
499
+ checkData , err := os .ReadFile (checkFilename )
500
500
if err != nil {
501
501
t .Fatalf ("Error on ReadFile('%s'): %s" , checkFilename , err .Error ())
502
502
}
@@ -550,14 +550,14 @@ func TestCompilationErrors(t *testing.T) {
550
550
}
551
551
for idx , match := range matches {
552
552
t .Run (fmt .Sprintf ("%03d-%s" , idx + 1 , match ), func (t * testing.T ) {
553
- testData , err := ioutil .ReadFile (match )
553
+ testData , err := os .ReadFile (match )
554
554
if err != nil {
555
555
t .Fatalf ("could not read file '%v': %v" , match , err )
556
556
}
557
557
tests := strings .Split (string (testData ), "\n " )
558
558
559
559
checkFilename := fmt .Sprintf ("%s.out" , match )
560
- checkData , err := ioutil .ReadFile (checkFilename )
560
+ checkData , err := os .ReadFile (checkFilename )
561
561
if err != nil {
562
562
t .Fatalf ("error on ReadFile('%s'): %s" , checkFilename , err .Error ())
563
563
}
@@ -628,7 +628,7 @@ func BenchmarkCache(b *testing.B) {
628
628
if err != nil {
629
629
b .Fatal (err )
630
630
}
631
- err = tpl .ExecuteWriterUnbuffered (tplContext , ioutil .Discard )
631
+ err = tpl .ExecuteWriterUnbuffered (tplContext , io .Discard )
632
632
if err != nil {
633
633
b .Fatal (err )
634
634
}
@@ -643,7 +643,7 @@ func BenchmarkCacheDebugOn(b *testing.B) {
643
643
if err != nil {
644
644
b .Fatal (err )
645
645
}
646
- err = tpl .ExecuteWriterUnbuffered (tplContext , ioutil .Discard )
646
+ err = tpl .ExecuteWriterUnbuffered (tplContext , io .Discard )
647
647
if err != nil {
648
648
b .Fatal (err )
649
649
}
@@ -657,15 +657,15 @@ func BenchmarkExecuteComplexWithSandboxActive(b *testing.B) {
657
657
}
658
658
b .ResetTimer ()
659
659
for i := 0 ; i < b .N ; i ++ {
660
- err = tpl .ExecuteWriterUnbuffered (tplContext , ioutil .Discard )
660
+ err = tpl .ExecuteWriterUnbuffered (tplContext , io .Discard )
661
661
if err != nil {
662
662
b .Fatal (err )
663
663
}
664
664
}
665
665
}
666
666
667
667
func BenchmarkCompileAndExecuteComplexWithSandboxActive (b * testing.B ) {
668
- buf , err := ioutil .ReadFile ("template_tests/complex.tpl" )
668
+ buf , err := os .ReadFile ("template_tests/complex.tpl" )
669
669
if err != nil {
670
670
b .Fatal (err )
671
671
}
@@ -677,7 +677,7 @@ func BenchmarkCompileAndExecuteComplexWithSandboxActive(b *testing.B) {
677
677
b .Fatal (err )
678
678
}
679
679
680
- err = tpl .ExecuteWriterUnbuffered (tplContext , ioutil .Discard )
680
+ err = tpl .ExecuteWriterUnbuffered (tplContext , io .Discard )
681
681
if err != nil {
682
682
b .Fatal (err )
683
683
}
@@ -692,7 +692,7 @@ func BenchmarkParallelExecuteComplexWithSandboxActive(b *testing.B) {
692
692
b .ResetTimer ()
693
693
b .RunParallel (func (pb * testing.PB ) {
694
694
for pb .Next () {
695
- err := tpl .ExecuteWriterUnbuffered (tplContext , ioutil .Discard )
695
+ err := tpl .ExecuteWriterUnbuffered (tplContext , io .Discard )
696
696
if err != nil {
697
697
b .Fatal (err )
698
698
}
@@ -708,15 +708,15 @@ func BenchmarkExecuteComplexWithoutSandbox(b *testing.B) {
708
708
}
709
709
b .ResetTimer ()
710
710
for i := 0 ; i < b .N ; i ++ {
711
- err = tpl .ExecuteWriterUnbuffered (tplContext , ioutil .Discard )
711
+ err = tpl .ExecuteWriterUnbuffered (tplContext , io .Discard )
712
712
if err != nil {
713
713
b .Fatal (err )
714
714
}
715
715
}
716
716
}
717
717
718
718
func BenchmarkCompileAndExecuteComplexWithoutSandbox (b * testing.B ) {
719
- buf , err := ioutil .ReadFile ("template_tests/complex.tpl" )
719
+ buf , err := os .ReadFile ("template_tests/complex.tpl" )
720
720
if err != nil {
721
721
b .Fatal (err )
722
722
}
@@ -731,7 +731,7 @@ func BenchmarkCompileAndExecuteComplexWithoutSandbox(b *testing.B) {
731
731
b .Fatal (err )
732
732
}
733
733
734
- err = tpl .ExecuteWriterUnbuffered (tplContext , ioutil .Discard )
734
+ err = tpl .ExecuteWriterUnbuffered (tplContext , io .Discard )
735
735
if err != nil {
736
736
b .Fatal (err )
737
737
}
@@ -747,7 +747,7 @@ func BenchmarkParallelExecuteComplexWithoutSandbox(b *testing.B) {
747
747
b .ResetTimer ()
748
748
b .RunParallel (func (pb * testing.PB ) {
749
749
for pb .Next () {
750
- err := tpl .ExecuteWriterUnbuffered (tplContext , ioutil .Discard )
750
+ err := tpl .ExecuteWriterUnbuffered (tplContext , io .Discard )
751
751
if err != nil {
752
752
b .Fatal (err )
753
753
}
0 commit comments