Require global settings file to use pkl:settings (#477)

This is technically a breaking change, but follows the intended use-case
and documentation of settings.

* Require that the global settings file at `~/.pkl/settings.pkl`
amends stdlib module `pkl:settings`, or otherwise sets `output.value`
to an instance of `pkl.Settings`.
* Simplify the object mapping of `PklSettings.java`
This commit is contained in:
Daniel Chao
2024-05-07 07:49:00 -07:00
committed by GitHub
parent aeb17588b3
commit 21aa44cfc4
5 changed files with 19 additions and 19 deletions

View File

@@ -2,6 +2,7 @@ package org.pkl.core.settings
import java.nio.file.Path
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatCode
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import org.pkl.commons.createParentDirectories
@@ -67,6 +68,13 @@ class PklSettingsTest {
checkEquals(Editor.VS_CODE, module.getProperty("vsCode") as PObject)
}
@Test
fun `invalid settings file`(@TempDir tempDir: Path) {
val settingsFile = tempDir.resolve("settings.pkl").apply { writeString("foo = 1") }
assertThatCode { PklSettings.loadFromPklHomeDir(tempDir) }
.hasMessageContaining("Expected `output.value` of module `${settingsFile.toUri()}` to be of type `pkl.settings`, but got type `settings`.")
}
private fun checkEquals(expected: Editor, actual: PObject) {
assertThat(actual.getProperty("urlScheme") as String).isEqualTo(expected.urlScheme)
}