mirror of
https://github.com/google/go-jsonnet.git
synced 2025-09-28 17:01:02 +02:00
Add test case for native function returning error
A native function returning an error should be reported as a runtime error, with a stack trace.
This commit is contained in:
parent
de6b2b8a55
commit
c7a5b68f1c
10
main_test.go
10
main_test.go
@ -19,6 +19,7 @@ package jsonnet
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path/filepath"
|
"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 {
|
type jsonnetInput struct {
|
||||||
name string
|
name string
|
||||||
input []byte
|
input []byte
|
||||||
@ -106,6 +115,7 @@ func runJsonnet(i jsonnetInput) jsonnetResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vm.NativeFunction(jsonToString)
|
vm.NativeFunction(jsonToString)
|
||||||
|
vm.NativeFunction(nativeError)
|
||||||
|
|
||||||
var output string
|
var output string
|
||||||
|
|
||||||
|
10
testdata/native_error.golden
vendored
Normal file
10
testdata/native_error.golden
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
RUNTIME ERROR: Native function error
|
||||||
|
-------------------------------------------------
|
||||||
|
testdata/native_error:1:1-28 $
|
||||||
|
|
||||||
|
std.native("nativeError")()
|
||||||
|
|
||||||
|
-------------------------------------------------
|
||||||
|
During evaluation
|
||||||
|
|
||||||
|
|
1
testdata/native_error.jsonnet
vendored
Normal file
1
testdata/native_error.jsonnet
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
std.native("nativeError")()
|
Loading…
x
Reference in New Issue
Block a user