-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
env: Add Env type and set() and get() functions
- Loading branch information
1 parent
df4fa6a
commit 36b31de
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
link_with("libc.so.6") | ||
|
||
// FIXME: These functions can return NULL, how do we check for this? | ||
// Do we promote NULL to an empty string? Do we return a Pointer instead? | ||
ext func getenv(name: string) -> string; | ||
ext func setenv(name: string, value: string); | ||
|
||
type Env(from: string); | ||
|
||
func get(env: Env) -> string { | ||
getenv(env.from) | ||
} | ||
|
||
func set(env: Env, new_value: string) { | ||
setenv(env.from, new_value) | ||
} | ||
|
||
// FIXME: Add assertions | ||
test get_home() { | ||
println(Env(from: "HOME").get()) | ||
} | ||
|
||
test set_var() { | ||
random_env_var = Env(from: "__jinko_RANDOM_ENV_VAR"); | ||
random_env_var.set("is_set") | ||
|
||
// random_env_var.get().should_be("is_set") | ||
} |