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

test output format #414

Open
yukulele opened this issue Apr 14, 2023 · 6 comments
Open

test output format #414

yukulele opened this issue Apr 14, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@yukulele
Copy link

yukulele commented Apr 14, 2023

Let's consider this command:

peggy math.peggy -t "1+2" > data.js

that generates this data.js file:

[ 'plus', 1, 2 ]

this output is a javascript statement but cant be used as a js file.

I suggest to add a --test-output-format option

examples:

  • with --test-output-format es:
export default [ 'plus', 1, 2 ]
  • with --test-output-format commonjs:
module.exports = [ 'plus', 1, 2 ]
  • with --test-output-format json:
[ "plus", 1, 2 ]

This is the way I currently work around this problem:

echo 'export default ' > data.js 
peggy math.peggy -t '1+2' >> data.js
@hildjj hildjj added the enhancement New feature or request label Apr 14, 2023
@hildjj
Copy link
Contributor

hildjj commented Apr 14, 2023

No objection. I probably won't implement this myself, but would be happy to help someone through submitting a patch for it.

@hildjj
Copy link
Contributor

hildjj commented Apr 14, 2023

Oh, I see that you closed this. I'm going to reopen it if that's ok, it's not a bad idea.

@hildjj hildjj reopened this Apr 14, 2023
@yukulele
Copy link
Author

Yes, I had closed this because I realized that the tests do not output javascript code but simply perform a console.log

Parsing it works with basic types (Plain object, array and primitive) but will not work with other types (Date, Set, Function, Symbol, ...)

So I'm not sure if this issue makes sense.

Eventually a JSON output could make sense but would be limited to stringifyable types.

@hildjj
Copy link
Contributor

hildjj commented Aug 11, 2023

It depends on what you want to do with the output. If you want relatively high-fidelity, we could output CBOR for instance.

@yukulele
Copy link
Author

a library like devalue could also be a solution.

@hildjj
Copy link
Contributor

hildjj commented Mar 11, 2024

I could imagine something like devalue output as an option, but it's not really pretty enough for human consumption. If you want JS out, maybe something like serialize-javascript or node-tosource?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants