make name the core block info
This commit is contained in:
@@ -16,6 +16,7 @@ import Testing
|
||||
|
||||
[[block]]
|
||||
command = "echo world"
|
||||
name = "world"
|
||||
"""
|
||||
|
||||
let blocks = try PHBlock.load(from: toml)
|
||||
@@ -25,7 +26,7 @@ import Testing
|
||||
#expect(blocks[0].name == "greeting")
|
||||
#expect(blocks[0].refresh == 5.0)
|
||||
#expect(blocks[0].label == nil)
|
||||
#expect(blocks[1].name == nil)
|
||||
#expect(blocks[1].name == "world")
|
||||
#expect(blocks[1].refresh == nil)
|
||||
}
|
||||
|
||||
@@ -73,11 +74,28 @@ private func makeBlocksConfigDir() throws -> URL {
|
||||
|
||||
// MARK: - Compute
|
||||
|
||||
@MainActor
|
||||
@Test func computeSeesBlockEnvironment() async throws {
|
||||
// The `[env]` section (overlaid by `BarController`) must reach the script's
|
||||
// process environment — this is the wiring the `env` config documents.
|
||||
let block = try PHBlock.load(from: """
|
||||
[[block]]
|
||||
name = "env"
|
||||
command = "echo $PHBAR_TEST_VAR"
|
||||
""")[0]
|
||||
block.environment = PHEnvironment(variables: ["PHBAR_TEST_VAR": "panini"])
|
||||
|
||||
let output = await block.compute()
|
||||
|
||||
#expect(output == "panini")
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Test func computeReturnsCommandStdout() async throws {
|
||||
let blocks = try PHBlock.load(from: """
|
||||
[[block]]
|
||||
command = "printf panini"
|
||||
name = "panini"
|
||||
""")
|
||||
|
||||
let output = await blocks[0].compute()
|
||||
@@ -95,6 +113,7 @@ private func makeBlocksConfigDir() throws -> URL {
|
||||
let blocks = try PHBlock.load(from: """
|
||||
[[block]]
|
||||
command = "pwd"
|
||||
name = "pwd"
|
||||
""")
|
||||
|
||||
let output = await blocks[0].compute()
|
||||
@@ -112,6 +131,7 @@ private func makeBlocksConfigDir() throws -> URL {
|
||||
let block = try PHBlock.load(from: """
|
||||
[[block]]
|
||||
command = "printf panini"
|
||||
name = "panini"
|
||||
""")[0]
|
||||
|
||||
#expect(block.label == nil)
|
||||
@@ -126,6 +146,7 @@ private func makeBlocksConfigDir() throws -> URL {
|
||||
let block = try PHBlock.load(from: """
|
||||
[[block]]
|
||||
command = "printf hi"
|
||||
name = "hi"
|
||||
""")[0]
|
||||
|
||||
block.startAutoRefresh()
|
||||
@@ -149,6 +170,7 @@ private func makeBlocksConfigDir() throws -> URL {
|
||||
let toml = """
|
||||
[[block]]
|
||||
command = "n=$(cat \(path) 2>/dev/null || echo 0); n=$((n+1)); echo $n > \(path); echo $n"
|
||||
name = "counter"
|
||||
refresh = 0.05
|
||||
"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user