@@ -2829,11 +2829,24 @@ func testMultipleUsers(t *testing.T, tester shellTester) {
2829
2829
func createSyntheticImportEntries (t testing.TB , numSyntheticEntries int ) {
2830
2830
homedir , err := os .UserHomeDir ()
2831
2831
require .NoError (t , err )
2832
- f , err := os .OpenFile (path .Join (homedir , ".bash_history" ), os .O_APPEND | os .O_CREATE | os .O_WRONLY , 0644 )
2832
+ filenames := []string {".bash_history" , ".zsh_history" , ".zhistory" }
2833
+ numFiles := len (filenames ) + 1 // The +1 accounts for the fish history file
2834
+ for _ , filename := range filenames {
2835
+ f , err := os .OpenFile (path .Join (homedir , filename ), os .O_APPEND | os .O_CREATE | os .O_WRONLY , 0644 )
2836
+ require .NoError (t , err )
2837
+ defer f .Close ()
2838
+ for i := 1 ; i <= numSyntheticEntries / numFiles ; i ++ {
2839
+ _ , err := f .WriteString (fmt .Sprintf ("echo command-%s-%d\n " , filename , i ))
2840
+ require .NoError (t , err )
2841
+ }
2842
+ require .NoError (t , f .Close ())
2843
+ }
2844
+ // Write the file for fish too, in the special fish format
2845
+ f , err := os .OpenFile (path .Join (homedir , ".local/share/fish/fish_history" ), os .O_APPEND | os .O_CREATE | os .O_WRONLY , 0644 )
2833
2846
require .NoError (t , err )
2834
2847
defer f .Close ()
2835
- for i := 1 ; i <= numSyntheticEntries ; i ++ {
2836
- _ , err := f .WriteString (fmt .Sprintf ("echo command-%d\n " , i ))
2848
+ for i := 1 ; i <= numSyntheticEntries / numFiles ; i ++ {
2849
+ _ , err := f .WriteString (fmt .Sprintf ("- cmd: echo command-fish -%d\n " , i ))
2837
2850
require .NoError (t , err )
2838
2851
}
2839
2852
require .NoError (t , f .Close ())
@@ -2868,10 +2881,26 @@ func TestImportHistory(t *testing.T) {
2868
2881
testutils .CompareGoldens (t , out , "TestImportHistory-export" )
2869
2882
}
2870
2883
2884
+ func TestAugmentedIsOfflineError (t * testing.T ) {
2885
+ defer testutils .BackupAndRestore (t )()
2886
+ installHishtory (t , zshTester {}, "" )
2887
+ defer testutils .BackupAndRestoreEnv ("HISHTORY_SIMULATE_NETWORK_ERROR" )()
2888
+ ctx := hctx .MakeContext ()
2889
+
2890
+ // By default, when the hishtory server is up, then IsOfflineError checks the error msg
2891
+ require .True (t , lib .CanReachHishtoryServer (ctx ))
2892
+ require .False (t , lib .IsOfflineError (ctx , fmt .Errorf ("unchecked error type" )))
2893
+
2894
+ // When the hishtory server is down, then all error messages are treated as being due to offline errors
2895
+ os .Setenv ("HISHTORY_SIMULATE_NETWORK_ERROR" , "1" )
2896
+ require .False (t , lib .CanReachHishtoryServer (ctx ))
2897
+ require .True (t , lib .IsOfflineError (ctx , fmt .Errorf ("unchecked error type" )))
2898
+ }
2899
+
2871
2900
func BenchmarkImport (b * testing.B ) {
2872
2901
b .StopTimer ()
2873
2902
// Setup
2874
- tester := bashTester {}
2903
+ tester := zshTester {}
2875
2904
defer testutils .BackupAndRestore (b )()
2876
2905
2877
2906
// Benchmark it
@@ -2881,7 +2910,7 @@ func BenchmarkImport(b *testing.B) {
2881
2910
installHishtory (b , tester , "" )
2882
2911
2883
2912
// Create a large history in bash that we will pre-import
2884
- numSyntheticEntries := 100_000
2913
+ numSyntheticEntries := 1_000_000
2885
2914
createSyntheticImportEntries (b , numSyntheticEntries )
2886
2915
2887
2916
// Benchmarked code:
@@ -2894,20 +2923,4 @@ func BenchmarkImport(b *testing.B) {
2894
2923
}
2895
2924
}
2896
2925
2897
- func TestAugmentedIsOfflineError (t * testing.T ) {
2898
- defer testutils .BackupAndRestore (t )()
2899
- installHishtory (t , zshTester {}, "" )
2900
- defer testutils .BackupAndRestoreEnv ("HISHTORY_SIMULATE_NETWORK_ERROR" )()
2901
- ctx := hctx .MakeContext ()
2902
-
2903
- // By default, when the hishtory server is up, then IsOfflineError checks the error msg
2904
- require .True (t , lib .CanReachHishtoryServer (ctx ))
2905
- require .False (t , lib .IsOfflineError (ctx , fmt .Errorf ("unchecked error type" )))
2906
-
2907
- // When the hishtory server is down, then all error messages are treated as being due to offline errors
2908
- os .Setenv ("HISHTORY_SIMULATE_NETWORK_ERROR" , "1" )
2909
- require .False (t , lib .CanReachHishtoryServer (ctx ))
2910
- require .True (t , lib .IsOfflineError (ctx , fmt .Errorf ("unchecked error type" )))
2911
- }
2912
-
2913
2926
// TODO: somehow test/confirm that hishtory works even if only bash/only zsh is installed
0 commit comments