github.com/markusbkk/elvish@v0.0.0-20231204143114-91dc52438621/pkg/eval/compiler_test.go (about) 1 package eval_test 2 3 import ( 4 "bytes" 5 "strings" 6 "testing" 7 8 . "github.com/markusbkk/elvish/pkg/eval" 9 "github.com/markusbkk/elvish/pkg/parse" 10 "github.com/markusbkk/elvish/pkg/prog/progtest" 11 ) 12 13 func TestDeprecatedBuiltin(t *testing.T) { 14 // There is no builtin deprecated for 0.18.x yet. Uncomment this when there is one. 15 //testCompileTimeDeprecation(t, "deprecated-builtin", `the "deprecated-builtin" command is deprecated`, 17) 16 17 // Deprecations of other builtins are implemented in the same way, so we 18 // don't test them repeatedly 19 } 20 21 func testCompileTimeDeprecation(t *testing.T, code, wantWarning string, level int) { 22 t.Helper() 23 progtest.SetDeprecationLevel(t, level) 24 25 ev := NewEvaler() 26 errOutput := new(bytes.Buffer) 27 28 parseErr, compileErr := ev.Check(parse.Source{Code: code}, errOutput) 29 if parseErr != nil { 30 t.Errorf("got parse err %v", parseErr) 31 } 32 if compileErr != nil { 33 t.Errorf("got compile err %v", compileErr) 34 } 35 36 warning := errOutput.String() 37 if !strings.Contains(warning, wantWarning) { 38 t.Errorf("got warning %q, want warning containing %q", warning, wantWarning) 39 } 40 }