Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix manifest json ex regression #516

Merged
merged 3 commits into from
Feb 15, 2021

Conversation

squat
Copy link
Contributor

@squat squat commented Feb 15, 2021

This PR fixes a regression in std.manifestJsonEx that caused the
standard library function to error when the given value was an array.
It also adds a test case to prevent regressions in
std.manifestJsonEx accepting arrays as values.

fixes: #515

Implements fix suggested by @sbarzowski in #515 (comment)

@google-cla google-cla bot added the cla: yes label Feb 15, 2021
@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 81.75% when pulling 0a41545 on squat:fix_manifestJsonEx_regression into f742f24 on google:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 81.75% when pulling 0a41545 on squat:fix_manifestJsonEx_regression into f742f24 on google:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 81.75% when pulling 0a41545 on squat:fix_manifestJsonEx_regression into f742f24 on google:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 81.75% when pulling 0a41545 on squat:fix_manifestJsonEx_regression into f742f24 on google:master.

@coveralls
Copy link

coveralls commented Feb 15, 2021

Coverage Status

Coverage increased (+0.04%) to 81.777% when pulling 860ee5c on squat:fix_manifestJsonEx_regression into f742f24 on google:master.

{
a: std.manifestJsonEx(a, ' '),
b: std.manifestJsonEx(b, ' '),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add examples of other data types, namely: null, string, number, bool. They all should work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds great 👍

testdata/builtinManifestJsonEx.jsonnet Show resolved Hide resolved
@@ -1211,11 +1211,6 @@ func jsonEncode(v interface{}) (string, error) {
// For backwards compatibility reasons, we are manually marshalling to json so we can control formatting
// In the future, it might be apt to use a library [pretty-printing] function
func builtinManifestJSONEx(i *interpreter, arguments []value) (value, error) {
obj, err := i.getObject(arguments[0])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Let's keep it named. value := arguments[0]. This way it's more clear what the args are.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling it value will shadow the type with the same name, which breaks the funcs that declare parameters of that type inside of the scope of buildinManifestJSONEx.
How about val?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. val sounds good.

This commit fixes a regression in std.manifestJsonEx that caused the
standard library function to error when the given value was an array.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
This commit adds a test case to prevent regressions in
std.manifestJsonEx accepting arrays as values.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
This commit adds test cases for more types to ensure that
std.manifestJsonEx continues to work with all types that may be given
as the `value` parameter.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
@squat squat force-pushed the fix_manifestJsonEx_regression branch from 0a41545 to 860ee5c Compare February 15, 2021 12:45
@sbarzowski sbarzowski merged commit 9b6cbef into google:master Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

std.manifestJsonEx breaking change in master
3 participants