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