github.com/go-graphite/carbonapi@v0.17.0/expr/corpus_test.go (about)

     1  package expr
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/go-graphite/carbonapi/pkg/parser"
    10  )
    11  
    12  func TestCorpus(t *testing.T) {
    13  
    14  	corpusFiles, err := filepath.Glob("workdir/crashers/*")
    15  	if err != nil {
    16  		t.Errorf("unable to glob: %v", err)
    17  	}
    18  
    19  	for _, corpusFile := range corpusFiles {
    20  
    21  		if strings.HasSuffix(corpusFile, ".quoted") || strings.HasSuffix(corpusFile, ".output") {
    22  			continue
    23  		}
    24  
    25  		t.Log(corpusFile)
    26  
    27  		contents, err := os.ReadFile(corpusFile)
    28  
    29  		if err != nil {
    30  			t.Errorf("error opening workdir/crashers/%s: %v", corpusFile, err)
    31  			return
    32  		}
    33  
    34  		_, rem, err := parser.ParseExpr(strings.TrimSpace(string(contents)))
    35  		if rem != "" || err != nil {
    36  			t.Errorf("error parsing: %s: %q: %v, rem=%q", corpusFile, contents, err, rem)
    37  		}
    38  	}
    39  
    40  }