mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-25 14:32:14 +02:00
Add tests for configuring displayed-columns
This commit is contained in:
parent
8b575e98c6
commit
267aa086fa
@ -1598,25 +1598,47 @@ func testConfigGetSet(t *testing.T, tester shellTester) {
|
|||||||
defer testutils.BackupAndRestore(t)()
|
defer testutils.BackupAndRestore(t)()
|
||||||
installHishtory(t, tester, "")
|
installHishtory(t, tester, "")
|
||||||
|
|
||||||
// Initially is true
|
// Config-get and set for enable-control-r
|
||||||
out := tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`)
|
out := tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`)
|
||||||
if out != "true" {
|
if out != "true" {
|
||||||
t.Fatalf("unexpected config-get output: %#v", out)
|
t.Fatalf("unexpected config-get output: %#v", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set to false and check
|
|
||||||
tester.RunInteractiveShell(t, `hishtory config-set enable-control-r false`)
|
tester.RunInteractiveShell(t, `hishtory config-set enable-control-r false`)
|
||||||
out = tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`)
|
out = tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`)
|
||||||
if out != "false" {
|
if out != "false" {
|
||||||
t.Fatalf("unexpected config-get output: %#v", out)
|
t.Fatalf("unexpected config-get output: %#v", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set to true and check
|
|
||||||
tester.RunInteractiveShell(t, `hishtory config-set enable-control-r true`)
|
tester.RunInteractiveShell(t, `hishtory config-set enable-control-r true`)
|
||||||
out = tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`)
|
out = tester.RunInteractiveShell(t, `hishtory config-get enable-control-r`)
|
||||||
if out != "true" {
|
if out != "true" {
|
||||||
t.Fatalf("unexpected config-get output: %#v", out)
|
t.Fatalf("unexpected config-get output: %#v", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// config for displayed-columns
|
||||||
|
out = tester.RunInteractiveShell(t, `hishtory config-get displayed-columns`)
|
||||||
|
if out != "Hostname CWD Timestamp Runtime \"Exit Code\" Command \n" {
|
||||||
|
t.Fatalf("unexpected config-get output: %#v", out)
|
||||||
|
}
|
||||||
|
tester.RunInteractiveShell(t, `hishtory config-set displayed-columns Hostname Command 'Exit Code'`)
|
||||||
|
out = tester.RunInteractiveShell(t, `hishtory config-get displayed-columns`)
|
||||||
|
if out != "Hostname Command \"Exit Code\" \n" {
|
||||||
|
t.Fatalf("unexpected config-get output: %#v", out)
|
||||||
|
}
|
||||||
|
tester.RunInteractiveShell(t, `hishtory config-add displayed-columns Timestamp`)
|
||||||
|
out = tester.RunInteractiveShell(t, `hishtory config-get displayed-columns`)
|
||||||
|
if out != "Hostname Command \"Exit Code\" Timestamp \n" {
|
||||||
|
t.Fatalf("unexpected config-get output: %#v", out)
|
||||||
|
}
|
||||||
|
tester.RunInteractiveShell(t, `hishtory config-delete displayed-columns Hostname`)
|
||||||
|
out = tester.RunInteractiveShell(t, `hishtory config-get displayed-columns`)
|
||||||
|
if out != "Command \"Exit Code\" Timestamp \n" {
|
||||||
|
t.Fatalf("unexpected config-get output: %#v", out)
|
||||||
|
}
|
||||||
|
tester.RunInteractiveShell(t, `hishtory config-add displayed-columns foobar`)
|
||||||
|
out = tester.RunInteractiveShell(t, `hishtory config-get displayed-columns`)
|
||||||
|
if out != "Command \"Exit Code\" Timestamp foobar \n" {
|
||||||
|
t.Fatalf("unexpected config-get output: %#v", out)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func clearControlRSearchFromConfig(t *testing.T) {
|
func clearControlRSearchFromConfig(t *testing.T) {
|
||||||
|
10
hishtory.go
10
hishtory.go
@ -126,8 +126,14 @@ func main() {
|
|||||||
case "enable-control-r":
|
case "enable-control-r":
|
||||||
fmt.Printf("%v", config.ControlRSearchEnabled)
|
fmt.Printf("%v", config.ControlRSearchEnabled)
|
||||||
case "displayed-columns":
|
case "displayed-columns":
|
||||||
// TODO: better formatting for the below
|
for _, col := range config.DisplayedColumns {
|
||||||
fmt.Printf("%#v", config.DisplayedColumns)
|
if strings.Contains(col, " ") {
|
||||||
|
fmt.Printf("%q ", col)
|
||||||
|
} else {
|
||||||
|
fmt.Print(col + " ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Print("\n")
|
||||||
case "custom-columns":
|
case "custom-columns":
|
||||||
// TODO: better formatting for this
|
// TODO: better formatting for this
|
||||||
fmt.Printf("%#v", config.CustomColumns)
|
fmt.Printf("%#v", config.CustomColumns)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user