mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-22 16:24:00 +01:00
Add a more complex test for custom columns
This commit is contained in:
parent
7d924409fb
commit
0e70347c0d
@ -155,6 +155,7 @@ func TestParameterized(t *testing.T) {
|
|||||||
t.Run("testConfigGetSet/"+tester.ShellName(), func(t *testing.T) { testConfigGetSet(t, tester) })
|
t.Run("testConfigGetSet/"+tester.ShellName(), func(t *testing.T) { testConfigGetSet(t, tester) })
|
||||||
t.Run("testControlR/"+tester.ShellName(), func(t *testing.T) { testControlR(t, tester, tester.ShellName()) })
|
t.Run("testControlR/"+tester.ShellName(), func(t *testing.T) { testControlR(t, tester, tester.ShellName()) })
|
||||||
t.Run("testHandleUpgradedFeatures/"+tester.ShellName(), func(t *testing.T) { testHandleUpgradedFeatures(t, tester) })
|
t.Run("testHandleUpgradedFeatures/"+tester.ShellName(), func(t *testing.T) { testHandleUpgradedFeatures(t, tester) })
|
||||||
|
t.Run("testCustomColumns/"+tester.ShellName(), func(t *testing.T) { testCustomColumns(t, tester) })
|
||||||
}
|
}
|
||||||
t.Run("testControlR/fish", func(t *testing.T) { testControlR(t, bashTester{}, "fish") })
|
t.Run("testControlR/fish", func(t *testing.T) { testControlR(t, bashTester{}, "fish") })
|
||||||
}
|
}
|
||||||
@ -1701,6 +1702,7 @@ func TestFish(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("fish is not installed")
|
t.Fatalf("fish is not installed")
|
||||||
}
|
}
|
||||||
|
// TODO: migrate this to the wrapper function
|
||||||
out := tester.RunInteractiveShell(t, ` export SHELL=`+fishLocation+`
|
out := tester.RunInteractiveShell(t, ` export SHELL=`+fishLocation+`
|
||||||
tmux kill-session -t foo || true
|
tmux kill-session -t foo || true
|
||||||
tmux -u new-session -d -x 200 -y 50 -s foo
|
tmux -u new-session -d -x 200 -y 50 -s foo
|
||||||
@ -1952,6 +1954,43 @@ func testControlR(t *testing.T, tester shellTester, shellName string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCustomColumns(t *testing.T, tester shellTester) {
|
||||||
|
// Setup
|
||||||
|
defer testutils.BackupAndRestore(t)()
|
||||||
|
installHishtory(t, tester, "")
|
||||||
|
|
||||||
|
// Record a few commands with no custom columns
|
||||||
|
out := tester.RunInteractiveShell(t, `export FOOBAR='hello'
|
||||||
|
echo $FOOBAR world
|
||||||
|
cd /
|
||||||
|
echo baz`)
|
||||||
|
if out != "hello world\nbaz\n" {
|
||||||
|
t.Fatalf("unexpected command output=%#v", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that the hishtory is saved correctly
|
||||||
|
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
|
||||||
|
compareGoldens(t, out, "testCustomColumns-initHistory")
|
||||||
|
|
||||||
|
// Configure a custom column
|
||||||
|
tester.RunInteractiveShell(t, `hishtory config-add custom-column git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || true'`)
|
||||||
|
|
||||||
|
// Run a few commands, some of which will have a git_remote
|
||||||
|
out = tester.RunInteractiveShell(t, `echo foo
|
||||||
|
cd /
|
||||||
|
echo bar`)
|
||||||
|
if out != "foo\nbar\n" {
|
||||||
|
t.Fatalf("unexpected command output=%#v", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// And check that it is all recorded correctly
|
||||||
|
tester.RunInteractiveShell(t, `hishtory config-set displayed-columns 'Exit Code' git_remote Command `)
|
||||||
|
out = tester.RunInteractiveShell(t, `hishtory query -pipefail`)
|
||||||
|
compareGoldens(t, out, "testCustomColumns-query")
|
||||||
|
out = captureTerminalOutput(t, tester, []string{"hishtory SPACE tquery SPACE -pipefail ENTER"})
|
||||||
|
compareGoldens(t, out, "testCustomColumns-tquery")
|
||||||
|
}
|
||||||
|
|
||||||
type deviceSet struct {
|
type deviceSet struct {
|
||||||
deviceMap *map[device]deviceOp
|
deviceMap *map[device]deviceOp
|
||||||
currentDevice *device
|
currentDevice *device
|
||||||
|
4
client/lib/goldens/testCustomColumns-initHistory
Normal file
4
client/lib/goldens/testCustomColumns-initHistory
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export FOOBAR='hello'
|
||||||
|
echo $FOOBAR world
|
||||||
|
cd /
|
||||||
|
echo baz
|
10
client/lib/goldens/testCustomColumns-query
Normal file
10
client/lib/goldens/testCustomColumns-query
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
Exit Code git_remote Command
|
||||||
|
0 git@github.com:ddworken/hishtory.git hishtory config-set displayed-columns 'Exit Code' git_remote Command
|
||||||
|
0 echo bar
|
||||||
|
0 cd /
|
||||||
|
0 git@github.com:ddworken/hishtory.git echo foo
|
||||||
|
0 git@github.com:ddworken/hishtory.git hishtory config-add custom-column git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || true'
|
||||||
|
0 echo baz
|
||||||
|
0 cd /
|
||||||
|
0 echo $FOOBAR world
|
||||||
|
0 export FOOBAR='hello'
|
31
client/lib/goldens/testCustomColumns-tquery
Normal file
31
client/lib/goldens/testCustomColumns-tquery
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
bash-5.2$ source /Users/david/.bashrc
|
||||||
|
bash-5.2$ hishtory tquery -pipefail
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Search Query: > -pipefail
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ Exit Code git_remote Command │
|
||||||
|
│─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||||
|
│ 0 git@github.com:ddworken/hishtory.git source /Users/david/.bashrc │
|
||||||
|
│ 0 git@github.com:ddworken/hishtory.git hishtory config-set displayed-columns 'Exit Code' git_remote Command │
|
||||||
|
│ 0 echo bar │
|
||||||
|
│ 0 cd / │
|
||||||
|
│ 0 git@github.com:ddworken/hishtory.git echo foo │
|
||||||
|
│ 0 git@github.com:ddworken/hishtory.git hishtory config-add custom-column git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || … │
|
||||||
|
│ 0 echo baz │
|
||||||
|
│ 0 cd / │
|
||||||
|
│ 0 echo $FOOBAR world │
|
||||||
|
│ 0 export FOOBAR='hello' │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
@ -166,6 +166,8 @@ func main() {
|
|||||||
config := hctx.GetConf(ctx)
|
config := hctx.GetConf(ctx)
|
||||||
key := os.Args[2]
|
key := os.Args[2]
|
||||||
switch key {
|
switch key {
|
||||||
|
case "custom-column":
|
||||||
|
fallthrough
|
||||||
case "custom-columns":
|
case "custom-columns":
|
||||||
columnName := os.Args[3]
|
columnName := os.Args[3]
|
||||||
command := os.Args[4]
|
command := os.Args[4]
|
||||||
|
Loading…
Reference in New Issue
Block a user