Skip to content

Commit 7e7e32f

Browse files
committed
!420 path@from-env in (liii path)
1 parent 08d6a55 commit 7e7e32f

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

GoldfishStandardLibrary.tmu

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,6 +3679,30 @@
36793679
\;
36803680
</scm-chunk>
36813681

3682+
<paragraph|path@from-env>
3683+
3684+
<\goldfish-chunk|goldfish/liii/path.scm|true|true>
3685+
(chained-define (@from-env name)
3686+
3687+
\ \ (path (getenv name)))
3688+
3689+
\;
3690+
</goldfish-chunk>
3691+
3692+
<\scm-chunk|tests/goldfish/liii/path-test.scm|true|true>
3693+
(when (os-linux?)
3694+
3695+
\ \ (check (path :from-env "HOME" :to-string) =\<gtr\> (path :home :to-string)))
3696+
3697+
\;
3698+
3699+
(when (os-windows?)
3700+
3701+
\ \ (check (path :from-env "USERPROFILE" :to-string) =\<gtr\> (path :home :to-string)))
3702+
3703+
\;
3704+
</scm-chunk>
3705+
36823706
\;
36833707

36843708
<subsection|谓词>

goldfish/liii/path.scm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@
140140
(else
141141
(loop ($ iter :drop 1 :get))))))))
142142

143+
(chained-define (@from-env name)
144+
(path (getenv name)))
145+
143146
(define (%file?)
144147
(path-file? (%to-string)))
145148

tests/goldfish/liii/path-test.scm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@
104104
(check (path "/tmp/") => (path :/ "tmp"))
105105
(check (path "/tmp/tmp2") => (path :/ "tmp" :/ "tmp2")))
106106

107+
(when (os-linux?)
108+
(check (path :from-env "HOME" :to-string) => (path :home :to-string)))
109+
110+
(when (os-windows?)
111+
(check (path :from-env "USERPROFILE" :to-string) => (path :home :to-string)))
112+
107113
(when (or (os-linux?) (os-macos?))
108114
(check-false (path :/ "tmp" :file?))
109115
(chdir "/tmp")

0 commit comments

Comments
 (0)