| 1 |
// SPDX-License-Identifier: MPL-2.0 |
| 2 |
// (c) Hare authors <https://harelang.org> |
| 3 |
|
| 4 |
use io; |
| 5 |
use os; |
| 6 |
use bufio; |
| 7 |
|
| 8 |
@test fn env() void = { |
| 9 |
let cmd = cmd("env")!; |
| 10 |
setenv(&cmd, "HARETEST", "vval")!; |
| 11 |
|
| 12 |
const (rd, wr) = pipe(); |
| 13 |
addfile(&cmd, os::stdout_file, wr)!; |
| 14 |
let proc = start(&cmd)!; |
| 15 |
io::close(wr)!; |
| 16 |
|
| 17 |
let sc = bufio::newscanner(rd); |
| 18 |
let found = for (let l => bufio::scan_line(&sc)!) { |
| 19 |
if (l == "HARETEST=vval") { |
| 20 |
break true; |
| 21 |
}; |
| 22 |
} else false; |
| 23 |
|
| 24 |
io::close(rd)!; |
| 25 |
wait(&proc)!; |
| 26 |
assert(found); |
| 27 |
}; |
| 28 |
|
| 29 |
@test fn args() void = { |
| 30 |
let cmd = cmd("env", "-i", "HARETEST=vval2")!; |
| 31 |
|
| 32 |
const (rd, wr) = pipe(); |
| 33 |
addfile(&cmd, os::stdout_file, wr)!; |
| 34 |
let proc = start(&cmd)!; |
| 35 |
io::close(wr)!; |
| 36 |
|
| 37 |
let sc = bufio::newscanner(rd); |
| 38 |
for (let l => bufio::scan_line(&sc)!) { |
| 39 |
assert(l == "HARETEST=vval2"); |
| 40 |
}; |
| 41 |
io::close(rd)!; |
| 42 |
wait(&proc)!; |
| 43 |
}; |
| 44 |
|
| 45 |
@test fn clearenv() void = { |
| 46 |
let cmd = cmd("env")!; |
| 47 |
clearenv(&cmd); |
| 48 |
setenv(&cmd, "HARETEST", "single")!; |
| 49 |
|
| 50 |
const (rd, wr) = pipe(); |
| 51 |
addfile(&cmd, os::stdout_file, wr)!; |
| 52 |
let proc = start(&cmd)!; |
| 53 |
io::close(wr)!; |
| 54 |
|
| 55 |
let sc = bufio::newscanner(rd); |
| 56 |
defer io::close(&sc)!; |
| 57 |
for (let l => bufio::scan_line(&sc)!) { |
| 58 |
assert(l == "HARETEST=single"); |
| 59 |
}; |
| 60 |
io::close(rd)!; |
| 61 |
wait(&proc)!; |
| 62 |
}; |