diff --git a/main_test.go b/main_test.go index afe86c6..d9ecaec 100644 --- a/main_test.go +++ b/main_test.go @@ -19,6 +19,7 @@ package jsonnet import ( "bytes" "encoding/json" + "errors" "flag" "io/ioutil" "path/filepath" @@ -81,6 +82,14 @@ var jsonToString = &NativeFunction{ }, } +var nativeError = &NativeFunction{ + Name: "nativeError", + Params: ast.Identifiers{}, + Func: func(x []interface{}) (interface{}, error) { + return nil, errors.New("Native function error") + }, +} + type jsonnetInput struct { name string input []byte @@ -106,6 +115,7 @@ func runJsonnet(i jsonnetInput) jsonnetResult { } vm.NativeFunction(jsonToString) + vm.NativeFunction(nativeError) var output string diff --git a/testdata/native_error.golden b/testdata/native_error.golden new file mode 100644 index 0000000..ce1f8b7 --- /dev/null +++ b/testdata/native_error.golden @@ -0,0 +1,10 @@ +RUNTIME ERROR: Native function error +------------------------------------------------- + testdata/native_error:1:1-28 $ + +std.native("nativeError")() + +------------------------------------------------- + During evaluation + + diff --git a/testdata/native_error.jsonnet b/testdata/native_error.jsonnet new file mode 100644 index 0000000..1851ac3 --- /dev/null +++ b/testdata/native_error.jsonnet @@ -0,0 +1 @@ +std.native("nativeError")()