mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
refactor: Fixed a number of memory leaks.
This commit is contained in:
@@ -34,11 +34,7 @@ test_usage_text_contains_steps :: proc(t: ^testing.T) {
|
||||
testing.expect(t, strings.contains(text, "4."), "missing step 4")
|
||||
testing.expect(t, strings.contains(text, "5."), "missing step 5")
|
||||
testing.expect(t, strings.contains(text, "> envr sync\n"), "step 4 missing 'envr sync'")
|
||||
testing.expect(
|
||||
t,
|
||||
strings.contains(text, "> envr restore"),
|
||||
"step 5 missing 'envr restore'",
|
||||
)
|
||||
testing.expect(t, strings.contains(text, "> envr restore"), "step 5 missing 'envr restore'")
|
||||
}
|
||||
|
||||
@(test)
|
||||
@@ -47,42 +43,37 @@ test_usage_text_contains_flags_and_help_hint :: proc(t: ^testing.T) {
|
||||
|
||||
testing.expect(t, strings.contains(text, "Flags:"), "missing Flags section")
|
||||
testing.expect(t, strings.contains(text, "--help"), "missing --help flag")
|
||||
testing.expect(
|
||||
t,
|
||||
strings.contains(text, "Use \"envr [command] --help\""),
|
||||
"missing help hint",
|
||||
)
|
||||
testing.expect(t, strings.contains(text, "Use \"envr [command] --help\""), "missing help hint")
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_command_help_backup :: proc(t: ^testing.T) {
|
||||
text, ok := command_help_text("backup")
|
||||
testing.expect(t, ok, "command_help_text(\"backup\") returned false")
|
||||
b: strings.Builder
|
||||
strings.builder_init(&b)
|
||||
defer strings.builder_destroy(&b)
|
||||
|
||||
ok := write_command_help("backup", strings.to_writer(&b))
|
||||
testing.expect(t, ok, "write_command_help(\"backup\") returned false")
|
||||
|
||||
text := strings.to_string(b)
|
||||
testing.expect(t, strings.contains(text, "Usage:"), "missing Usage line")
|
||||
testing.expect(
|
||||
t,
|
||||
strings.contains(text, "envr backup <path>"),
|
||||
"missing usage pattern",
|
||||
)
|
||||
testing.expect(
|
||||
t,
|
||||
strings.contains(text, "Aliases:"),
|
||||
"missing Aliases section",
|
||||
)
|
||||
testing.expect(t, strings.contains(text, "envr backup <path>"), "missing usage pattern")
|
||||
testing.expect(t, strings.contains(text, "Aliases:"), "missing Aliases section")
|
||||
testing.expect(t, strings.contains(text, "add"), "missing 'add' alias")
|
||||
testing.expect(t, strings.contains(text, "Flags:"), "missing Flags section")
|
||||
testing.expect(
|
||||
t,
|
||||
strings.contains(text, "--help"),
|
||||
"missing --help in flags",
|
||||
)
|
||||
testing.expect(t, strings.contains(text, "--help"), "missing --help in flags")
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_command_help_add_alias :: proc(t: ^testing.T) {
|
||||
text, ok := command_help_text("add")
|
||||
testing.expect(t, ok, "command_help_text(\"add\") returned false")
|
||||
b: strings.Builder
|
||||
strings.builder_init(&b)
|
||||
defer strings.builder_destroy(&b)
|
||||
|
||||
ok := write_command_help("add", strings.to_writer(&b))
|
||||
testing.expect(t, ok, "write_command_help(\"add\") returned false")
|
||||
|
||||
text := strings.to_string(b)
|
||||
testing.expect(
|
||||
t,
|
||||
strings.contains(text, "envr backup <path>"),
|
||||
@@ -93,34 +84,43 @@ test_command_help_add_alias :: proc(t: ^testing.T) {
|
||||
|
||||
@(test)
|
||||
test_command_help_init_no_aliases :: proc(t: ^testing.T) {
|
||||
text, ok := command_help_text("init")
|
||||
testing.expect(t, ok, "command_help_text(\"init\") returned false")
|
||||
b: strings.Builder
|
||||
strings.builder_init(&b)
|
||||
defer strings.builder_destroy(&b)
|
||||
|
||||
ok := write_command_help("init", strings.to_writer(&b))
|
||||
testing.expect(t, ok, "write_command_help(\"init\") returned false")
|
||||
|
||||
text := strings.to_string(b)
|
||||
testing.expect(t, strings.contains(text, "Usage:"), "missing Usage line")
|
||||
testing.expect(
|
||||
t,
|
||||
!strings.contains(text, "Aliases:"),
|
||||
"init should not have Aliases section",
|
||||
)
|
||||
testing.expect(t, !strings.contains(text, "Aliases:"), "init should not have Aliases section")
|
||||
testing.expect(t, strings.contains(text, "Flags:"), "missing Flags section")
|
||||
testing.expect(
|
||||
t,
|
||||
strings.contains(text, "help for init"),
|
||||
"missing 'help for init'",
|
||||
)
|
||||
testing.expect(t, strings.contains(text, "help for init"), "missing 'help for init'")
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_command_help_unknown :: proc(t: ^testing.T) {
|
||||
text, ok := command_help_text("nonexistent")
|
||||
testing.expect(t, !ok, "command_help_text(\"nonexistent\") should return false")
|
||||
b: strings.Builder
|
||||
strings.builder_init(&b)
|
||||
defer strings.builder_destroy(&b)
|
||||
|
||||
ok := write_command_help("nonexistent", strings.to_writer(&b))
|
||||
testing.expect(t, !ok, "write_command_help(\"nonexistent\") should return false")
|
||||
|
||||
text := strings.to_string(b)
|
||||
testing.expect(t, len(text) == 0, "text should be empty for unknown command")
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_command_help_version :: proc(t: ^testing.T) {
|
||||
text, ok := command_help_text("version")
|
||||
testing.expect(t, ok, "command_help_text(\"version\") returned false")
|
||||
b: strings.Builder
|
||||
strings.builder_init(&b)
|
||||
defer strings.builder_destroy(&b)
|
||||
|
||||
ok := write_command_help("version", strings.to_writer(&b))
|
||||
testing.expect(t, ok, "write_command_help(\"version\") returned false")
|
||||
|
||||
text := strings.to_string(b)
|
||||
testing.expect(t, strings.contains(text, "Usage:"), "missing Usage line")
|
||||
testing.expect(
|
||||
t,
|
||||
@@ -128,3 +128,4 @@ test_command_help_version :: proc(t: ^testing.T) {
|
||||
"version should not have Aliases section",
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user