Commit Graph

48 Commits

Author SHA1 Message Date
guoguangwu
04f3751f08
chore: remove refs to deprecated io/ioutil (#716) 2024-06-10 21:27:07 +01:00
Rudo Thomas
b42132a7a3 feat: Report native function panics as runtime errors.
Previously, you'd get an "INTERNAL ERROR: (CRASH)" with a full backtrace
and a link to file a bug against go-jsonnet.
2022-07-03 21:39:29 +01:00
Harsimran Singh Maan
1b7cbff4cd Add github actions ci 2021-05-19 16:00:28 +02:00
Stanisław Barzowski
b70cbd441a Anonymous Import Locations
We used to treat dummy paths like <stdin>, <std>, <extvar> as
real import locations, which causes obvious problem for importers.

After this change we consistently pass "" (an empty string) as location
for non-imported paths.

We exposed new functions to properly handle all paths.

The first function family, EvaluateFile* which allow evaluating
a Jsonnet program at a specified importable path. It should
be used in most cases.

The second function family, EvaluateAnonymousSnippet* allows evaluating
a snippet without an importable path. It should be used for situations
like the code passed as a commandline argument, stdin, etc.

The old function family, EvaluateSnippet* is now deprecated, but
works the same as before, i.e. the passed filenames are treated
as imported paths.

Changes are required to custom importers to make sure they satisfy
the refined contract.

Fixes #329.
2020-09-08 17:27:47 +02:00
Stanisław Barzowski
3a245f70d4 Preparation for linter.
* Extract some test utilities to a separate package.
* Rename some test utilities.
* Internally expose DirectChildren.
* Add LocationRange to some non-expr AST parts,
  such as local binds, parameters and object fields.
* Add end-of-file-reached testcases.
2020-03-15 14:38:40 +01:00
Dave Cunningham
724650d358
Add native golang formatter (#388)
Add native golang formatter
2020-03-10 22:19:49 +00:00
Stanisław Barzowski
9ada769ce4 Make golangci-lint happy
Some of the suggestions are minor bug fixes (missing error handling).
2020-03-05 14:54:27 +01:00
Dave Cunningham
5476fefb25 Add ParseParameter. Also fell down the rabbithole improving content and consistency of parse errors 2020-03-05 09:33:21 +01:00
Stanisław Barzowski
45f3912215 Make parser package internal
There is no reason for external users to directly depend
on parser. It had a few random things exported as well,
namely errors and "children" functions (helpers for AST
traversal).

It was easy to extract the errors package, but I needed to leave
children in parser for now. The errors package was also
made internal, but it's a candidate for making it public
again potentially (if someone wants to display error messages
just like us). For now it's probably too incomplete anyway.

This change has a potential of breaking the existing users
since we technically remove public APIs. These were not needed
or even helpful for actually running Jsonnet code, but perhaps
someone used them anyway.
2019-09-03 17:28:33 +02:00
Stanisław Barzowski
82f949e7fe Extract AST processing to separate packages
Making it independent from the jsonnet package breaks the circular
dependency during stdast generation.
2019-08-28 20:16:47 +01:00
Steve Harris
7614fd519c Correct a few complaints reported by "staticcheck" 2019-06-15 01:34:11 +02:00
Steve Harris
b6bb47abee Move escaped filename tests into separate function
Write the files with verboten names (within some operating systems) to
a temporary directory, in order to avoid committing them to the VCS
repository.
2019-06-15 01:34:11 +02:00
Steve Harris
7084acc012 Accommodate testing with Bazel 2019-06-15 01:34:11 +02:00
Stanisław Barzowski
aa47869bc4 Add basic tests for Children and add missing cases 2019-03-20 10:23:24 -04:00
Luke Granger-Brown
643210d274 Add string output support for multifile output (#220)
* Add test support for multi-file output.

* Add -update support for multi-file output tests.

* Add support for string output in multi-file output mode.

* Rename 'stringOutput' to 'stringOutputMode' to better express what it does

* Refactor main_test to make it less nested.

This also causes the -update flag to output a list of files which
have been updated. This does not include the paths which are deleted
for multi-file tests.
2018-05-09 11:49:07 -04:00
Marcelo Cantos
b0459e4867 Add AppVeyor Windows builds and releases (#206)
* Make some filenames Windows-friendly

* Update references to renamed files

* Fix escaped filenames to run on non-Windows platforms
2018-03-12 20:46:57 -04:00
Marcelo Cantos
ed5f280c59 Apply golint recommendations (#196)
* Apply golint recommendations
2018-02-26 14:12:25 -05:00
Stanisław Barzowski
34a24d8bcb Basic support for running jsonnet command in tests (#167)
A step towards a unified test suite. In particular this
lets us use C++ version with Go tests. The problem remains
that errors (both static and runtime) may differ between implementations.
This will require special handling. C++ version seems to pass all
"positive" tests. Go version also has this problem (error formatter used in tests is different).

Also native functions etc. are not handled in any way at the moment.
2018-01-10 21:27:44 -05:00
Cam Hutchison
c7a5b68f1c 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.
2017-12-18 10:22:53 -05:00
Stanisław Barzowski
c3551f4f61 Basic refactoring - towards shared e2e tests 2017-12-14 17:48:34 -05:00
Daniel Theophanes
691e8d4f3c Remove unused dependencies
The imports in "_gen.go" were not used, compiled, or
apparently useful so remove.

The color field in the ErrorFormatter was never set
to true and never used. This brought in many unused
dependencies including x/sys/unix that aren't ever
used. Move the color dependencies to the jsonnet main
package and set the colorized output there. Turn the
exported ErrorFormatter into an interface. In the future
it could be used to export JSON or HTML output.

Fixes google/go-jsonnet#131
2017-12-12 00:05:28 -05:00
Dave Cunningham
c60056c75f
Feature-complete commandline interface (#138)
* Feature-complete commandline interface
* Make errors match cpp implementation
2017-11-03 22:00:30 -04:00
Dave Cunningham
b6ee2c2f51
String token end location off-by-one error (#139)
* String token end location off-by-one error
2017-11-03 21:36:31 -04:00
Dave Cunningham
f965f9ee04
For compatability, emit the \n within the library, not the cmd (#137)
* For compatability, emit the \n within the library, not the commandline tool
* Also add manifestString to library
2017-10-29 21:41:01 -04:00
Dave Cunningham
968ae23435 Make NativeFunction members public (#135)
* Make NativeFunction members public
2017-10-24 23:00:40 -04:00
Alex Clemmer
52d2fdcfde Rename jsonnet.nativeFunction -> jsonnet.NativeFunction
Currently, `jsonnet.VM#NativeFunction` takes a single argument of type
`jsonnet.nativeFunction`. This is ok for internal use, but because this
type is private to the `jsonnet` package, it is not possible for a
third party to call this function (since it can't instantiate the type).

This commit makes this type public to remedy this problem.
2017-10-24 21:53:52 -04:00
Stanisław Barzowski
ed281bc563 Support for native callbacks 2017-10-13 15:49:06 -04:00
Stanisław Barzowski
96a2abc46c Some initial test metadata
It will be useful for properly testing TLAs, import callbacks etc.
2017-10-13 15:34:00 -04:00
Stanisław Barzowski
171cdd67f9 Post-rebase fix
Dead code removed in one branch, ended up being used in another.
2017-10-10 18:57:58 -04:00
Stanisław Barzowski
0c43340142 Support for import callbacks
It was already there, it was a matter of exposing it in the API
2017-10-10 00:31:02 -04:00
Stanisław Barzowski
ba0f236b14 Optional eval (#92)
* Optional arguments
2017-10-10 00:06:14 -04:00
Stanisław Barzowski
a4058fc177 Support for stack trace size limit 2017-10-05 03:31:16 -04:00
Stanisław Barzowski
c3459153df Location, error formatting and stack trace improvements (#59)
* Location, error formatting and stack trace improvements

* Static context for AST nodes
* Thunks no longer need `name`
* Prototype for showing snippets in error messages (old format still
available)
* Use ast.Function to represent methods and local function sugar.
* Change tests so that the error output is pretty
2017-10-03 14:27:44 -04:00
Stanisław Barzowski
b1a9c0bd6d ExtVar support 2017-09-28 23:14:53 -04:00
Stanisław Barzowski
fe62ec46a8 Improve imports (#66)
* Improve imports

* Nonexistent file is now a runtime error (used to be ignored)
* Permission denied is a runtime error (used to be an internal error)
* Basic tests added for imports
* Renamed tests from .input to .jsonnet
	* It's standard
	* It's compatible with C++ test suite
	* Editors enable syntax highlighting based on extension
	* Importing .input looks weird
2017-09-22 18:03:00 -04:00
Stanisław Barzowski
77b8b9e335 Optional args parser/lexer/ast support (#33)
* Optional args parser/lexer/ast support

Just "frontend" part. They are ignored during actual execution.
2017-09-06 11:53:10 -04:00
Stanisław Barzowski
5da57ac417 Interpreter & runtime - minimal usable version (#24)
* Interpreter & runtime - minimal usable version

Accomplishments in this commit:
* Majority of language features implemented:
	* Unary operators
	* Binary operators
	* Conditionals
	* Errors
	* Indexing arrays
	* Indexing objects
	* Object inheritance
	* Imports
	* Functions
	* Function calls
* There is a quite nice way for creating builtins
* Static analyzer is there with most of the functionality
* Standard library is included and parts unaffected by missing features
work
* Some bugs in existing parts fixed
* Most positive tests from C++ version pass, the rest is failing mostly
due to missing builtins and comprehensions.
* Some initial structure was created that should allow more incremental
  and focused changes in the future PRs.
* Some comments/explanations added
* Panics translated to a little bit more gentle internal errors (with a
  link to issues on github).

What still sucks:
* Stack traces & error messages (there's some stuff in place)
* Almost everything is in the same package
* Stuff is exported or unexporeted randomly (see above)
* Missing a few lexing/parsing features
* Missing builtins
* Missing support for extvars and top-level-args
* Checking function arguments is missing
* No clean Go API that commandline and compatibility layer to C can use
* No compatibility layer to C
* Assertions don't work (desugaring level, assertEquals works).
* Manifestation stack traces (and generally it could use some work).
* The way environments are constructed is sometimes suboptimal/clumsy.
2017-08-24 20:09:10 -04:00
Sevki
7b875bd141 change the diff function
the proposed change would remove the dependency of a diff binary
in favour of using a library

Signed-off-by: Sevki <s@sevki.org>
2017-08-18 00:19:43 +02:00
Sevki
f53577632f refactor golden tests to look more like std library tests
this commit proposes using a file based golden tests approach,
parts of this refactor uses code and conventions from the go std
library. At it's current state go-jsonnet does not support many of
the examples on http://jsonnet.org/docs/demo.html, motive behind
the refactor is to add the demo examples to the test suite and
the demo examples are too big to be inlined.

Signed-off-by: Sevki <s@sevki.org>
2017-08-16 23:59:55 +02:00
Sevki
4582b1c4ae remove errString from main_test.go
since non of the test cases actually use the err string field and
the golden file testing pattern does not really need it, this commit
proposes the removal of the errString field from tests

Signed-off-by: Sevki <s@sevki.org>
2017-08-16 23:07:31 +02:00
Sevki
640983c125 use t.Run for tests
using `t.Run` instead including the test name in error message is
a more idiomatic way of testing things in go. Since this feature
was added to go in 1.7 release and the travis config explicitly
specifies 1.4 and 1.5 (2 and 2,5 year old releases) as test targets
this change will break the CI builds, therefore this commit also
proposes dropping those releases in favour of adding a newer
version of go (1.8) as the test target.

Signed-off-by: Sevki <s@sevki.org>
2017-08-16 23:03:05 +02:00
Stanisław Barzowski
899b931c07 Fix unicode escape sequences & some desugaring 2017-08-16 12:08:28 -04:00
Stanisław Barzowski
a94bfef764 Add verbatim string support 2017-08-10 17:29:04 -04:00
Stanisław Barzowski
badeb833bb Tests + default + better panic message 2017-07-31 11:49:20 -04:00
Stanisław Barzowski
964c4bc0df Allow adding strings 2017-07-28 17:23:27 -04:00
Dave Cunningham
09c7c8c7c0 Pass through JSON 2016-04-04 02:16:03 -04:00
Joe Beda
0eedf437b1 Fix up lint errors.
Also:
* Made all types used in errors public.
* Made interpreter receiver a pointer.  This will reduce GC load for deep stacks.
2016-03-14 12:50:42 +00:00
Dave Cunningham
563bbe12f4 First end-to-end test (addition of numbers) 2016-03-08 01:17:44 -05:00