From e5e0446c5a6b089085eaad31491bbd346d1643a7 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Wed, 15 Jul 2020 00:04:03 +0100 Subject: [PATCH] Warn about deprecated syntax features in imported modules. This fixes #1072. --- pkg/eval/builtin_fn_misc.go | 2 +- pkg/eval/builtin_special.go | 2 +- pkg/eval/builtin_special_test.go | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/eval/builtin_fn_misc.go b/pkg/eval/builtin_fn_misc.go index d98576fa..f1cbc5a4 100644 --- a/pkg/eval/builtin_fn_misc.go +++ b/pkg/eval/builtin_fn_misc.go @@ -283,7 +283,7 @@ func source(fm *Frame, fname string) error { return err } src := parse.Source{Name: fname, Code: code, IsFile: true} - tree, err := parse.Parse(src) + tree, err := parse.ParseWithDeprecation(src, fm.ports[2].File) if err != nil { return err } diff --git a/pkg/eval/builtin_special.go b/pkg/eval/builtin_special.go index de133cf6..cc429cc3 100644 --- a/pkg/eval/builtin_special.go +++ b/pkg/eval/builtin_special.go @@ -299,7 +299,7 @@ func loadModuleFile(fm *Frame, r diag.Ranger, spec, path string) (Ns, error) { } func evalModule(fm *Frame, r diag.Ranger, key string, src parse.Source) (Ns, error) { - tree, err := parse.Parse(src) + tree, err := parse.ParseWithDeprecation(src, fm.ports[2].File) if err != nil { return nil, err } diff --git a/pkg/eval/builtin_special_test.go b/pkg/eval/builtin_special_test.go index 4b37d243..f69aeb17 100644 --- a/pkg/eval/builtin_special_test.go +++ b/pkg/eval/builtin_special_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/elves/elvish/pkg/eval/errs" + "github.com/elves/elvish/pkg/prog" "github.com/elves/elvish/pkg/util" ) @@ -160,3 +161,17 @@ func TestUse(t *testing.T) { That("use a b c").DoesNotCompile(), ) } + +// Regression test for #1072 +func TestUse_WarnsAboutDeprecatedSyntax(t *testing.T) { + restore := prog.SetShowDeprecations(true) + defer restore() + libdir, cleanup := util.InTestDir() + defer cleanup() + mustWriteFile("dep.elv", []byte("a = \\\n1"), 0600) + + TestWithSetup(t, func(ev *Evaler) { ev.SetLibDir(libdir) }, + // Importing module triggers check for deprecated syntax features + That("use dep").PrintsStderrWith("is deprecated"), + ) +}