mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 01:47:51 +08:00
1e0885310e
When attempting to update a read-only var return an error struct rather
than a simple string (i.e., a Go `error` type). This makes it possible
to include the var name in the error message. This builds on commit
a33ecb2d
that highlights the offending var name in the stack trace but
does not include the var name in the error message. With this change the
error message includes the offending var name.
Related #255
20 lines
346 B
Go
20 lines
346 B
Go
package vars
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"src.elv.sh/pkg/eval/errs"
|
|
)
|
|
|
|
func TestNewReadOnly(t *testing.T) {
|
|
v := NewReadOnly("haha")
|
|
if v.Get() != "haha" {
|
|
t.Errorf("Get doesn't return initial value")
|
|
}
|
|
|
|
err := v.Set("lala")
|
|
if _, ok := err.(errs.SetReadOnlyVar); !ok {
|
|
t.Errorf("Set a readonly var doesn't error as expected: %#v", err)
|
|
}
|
|
}
|