Skip to content

Fixes for main method#174

Merged
lihaoyi-databricks merged 5 commits intomasterfrom
fix-main
Jun 6, 2023
Merged

Fixes for main method#174
lihaoyi-databricks merged 5 commits intomasterfrom
fix-main

Conversation

@lihaoyi-databricks
Copy link
Copy Markdown
Contributor

@lihaoyi-databricks lihaoyi-databricks commented Jun 5, 2023

Bug fixes and unit tests to validate behavior of various command line flags and their combinations: --exec, --yaml-out, --yaml-stream, --multi, --output-file. I also propagated the std: Std argument all the way to sjsonnet.SjsonnetMain.main0, so it can easily be passed in by people who use the CLI-arg-based programmatic interface without having to drop down into sjsonnet.Interpreter, e.g. in Databricks' JsonnetWorker

Fixes #112, and fixes #77, and adds tests for #60 (which was already working before, but without test coverage)

The logic inside SjsonnetMain.scala is still pretty messy, but at least it has some rudimentary unit tests now.

Another thing to note is that trailing newline handling isn't great; depending on what code path you go through, you may get zero, one, or two trailing newlines. That should be benign, since trailing newlines are not semantically meaningful in either JSON or YAML, so for now I just left them in place. At least now we have tests to surface some of the weirdness

I had to move MainTests.scala from src-jvm-native/ to src-jvm/, due to weird crashes in the Scala Native test-running infrastructure. Given the experimental nature of Scala-Native, losing a bit of coverage is probably OK for now, and also it's unlikely that this will cause anything to break given the same code receives test coverage on the JVM.

Copy link
Copy Markdown
Collaborator

@szeiger szeiger left a comment

Choose a reason for hiding this comment

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

Can we also support - input on the command line now that the file reading happens later? It's very useful in the C++ version.

std: Val.Obj = new Std().Std): Either[String, String] = {

val (jsonnetCode, path) =
if (config.exec.value) (file, wd / "<exec>") else (os.read(os.Path(file)), os.Path(file))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Abusing file to be the source code is rather ugly.

@lihaoyi-databricks lihaoyi-databricks merged commit c729e28 into master Jun 6, 2023
@lihaoyi-databricks
Copy link
Copy Markdown
Contributor Author

Yes, let me open up another PR

@stephenamar-db stephenamar-db deleted the fix-main branch April 18, 2025 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants