mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
refactor: Fixed memory leaks in find_binary.
This commit is contained in:
34
features_test.odin
Normal file
34
features_test.odin
Normal file
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import "core:os"
|
||||
import "core:strings"
|
||||
import "core:testing"
|
||||
|
||||
@(test)
|
||||
test_find_binary_exists :: proc(t: ^testing.T) {
|
||||
path := os.get_env("PATH", context.allocator)
|
||||
paths := strings.split(path, ":")
|
||||
|
||||
result := find_binary(paths, "sh")
|
||||
testing.expect(t, result != "", "sh should be found on PATH")
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_find_binary_not_exists :: proc(t: ^testing.T) {
|
||||
old_path := os.get_env("PATH", context.allocator)
|
||||
defer {
|
||||
if old_path != "" {
|
||||
os.set_env("PATH", old_path)
|
||||
}
|
||||
}
|
||||
|
||||
os.set_env("PATH", "/tmp/envr-nope")
|
||||
|
||||
path := os.get_env("PATH", context.allocator)
|
||||
paths := strings.split(path, ":")
|
||||
|
||||
|
||||
result := find_binary(paths, "no_such_binary_xyz")
|
||||
testing.expect(t, result == "", "nonexistent binary should not be found")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user