xref: /openbsd/regress/bin/ksh/history.t (revision 09467b48)
1#	$OpenBSD: history.t,v 1.4 2017/10/23 17:16:10 anton Exp $
2
3# Not tested yet:
4#	- commands in history file are not numbered negatively
5# (and a few hundred other things)
6
7name: history-basic
8description:
9	See if we can test history at all
10arguments: !-i!
11env-setup: !ENV=./Env!HISTFILE=hist.file!
12file-setup: file 644 "Env"
13	PS1=X
14stdin:
15	echo hi
16	fc -l
17expected-stdout:
18	hi
19	1	echo hi
20expected-stderr-pattern:
21	/^X*$/m
22---
23
24name: history-e-minus-1
25description:
26	Check if more recent command is executed
27arguments: !-i!
28env-setup: !ENV=./Env!HISTFILE=hist.file!
29file-setup: file 644 "Env"
30	PS1=X
31stdin:
32	echo hi
33	echo there
34	fc -e -
35expected-stdout:
36	hi
37	there
38	there
39expected-stderr-pattern:
40	/^X*echo there\nX*$/m
41---
42
43name: history-e-minus-2
44description:
45	Check that repeated command is printed before command
46	is re-executed.
47arguments: !-i!
48env-setup: !ENV=./Env!HISTFILE=hist.file!
49file-setup: file 644 "Env"
50	PS1=X
51stdin:
52	exec 2>&1
53	echo hi
54	echo there
55	fc -e -
56expected-stdout-pattern:
57	/X*hi\nX*there\nX*echo there\nthere\nX*/
58expected-stderr-pattern:
59	/^X*$/m
60---
61
62name: history-e-minus-3
63description:
64	fc -e - fails when there is no history
65	(ksh93 has a bug that causes this to fail)
66	(ksh88 loops on this)
67arguments: !-i!
68env-setup: !ENV=./Env!HISTFILE=hist.file!
69file-setup: file 644 "Env"
70	PS1=X
71stdin:
72	fc -e -
73	echo ok
74expected-stdout:
75	ok
76expected-stderr-pattern:
77	/^X*.*:.*history.*\nX*$/m
78---
79
80name: history-e-minus-4
81description:
82	Check if "fc -e -" command output goes to stdout.
83arguments: !-i!
84env-setup: !ENV=./Env!HISTFILE=hist.file!
85file-setup: file 644 "Env"
86	PS1=X
87stdin:
88	echo abc
89	fc -e - | (read x; echo "A $x")
90	echo ok
91expected-stdout:
92	abc
93	A abc
94	ok
95expected-stderr-pattern:
96	/^X*echo abc\nX*/m
97---
98
99name: history-e-minus-5
100description:
101	fc is replaced in history by new command.
102arguments: !-i!
103env-setup: !ENV=./Env!HISTFILE=hist.file!
104file-setup: file 644 "Env"
105	PS1=X
106stdin:
107	echo abc def
108	echo ghi jkl
109	fc -e - echo
110	fc -l 2 4
111expected-stdout:
112	abc def
113	ghi jkl
114	ghi jkl
115	2	echo ghi jkl
116	3	echo ghi jkl
117	4	fc -l 2 4
118expected-stderr-pattern:
119	/^X*echo ghi jkl\nX*$/m
120---
121
122name: history-list-1
123description:
124	List lists correct range
125	(ksh88 fails 'cause it lists the fc command)
126arguments: !-i!
127env-setup: !ENV=./Env!HISTFILE=hist.file!
128file-setup: file 644 "Env"
129	PS1=X
130stdin:
131	echo line 1
132	echo line 2
133	echo line 3
134	fc -l -- -2
135expected-stdout:
136	line 1
137	line 2
138	line 3
139	2	echo line 2
140	3	echo line 3
141expected-stderr-pattern:
142	/^X*$/m
143---
144
145name: history-list-2
146description:
147	Lists oldest history if given pre-historic number
148	(ksh93 has a bug that causes this to fail)
149	(ksh88 fails 'cause it lists the fc command)
150arguments: !-i!
151env-setup: !ENV=./Env!HISTFILE=hist.file!
152file-setup: file 644 "Env"
153	PS1=X
154stdin:
155	echo line 1
156	echo line 2
157	echo line 3
158	fc -l -- -40
159expected-stdout:
160	line 1
161	line 2
162	line 3
163	1	echo line 1
164	2	echo line 2
165	3	echo line 3
166expected-stderr-pattern:
167	/^X*$/m
168---
169
170name: history-list-3
171description:
172	Can give number `options' to fc
173arguments: !-i!
174env-setup: !ENV=./Env!HISTFILE=hist.file!
175file-setup: file 644 "Env"
176	PS1=X
177stdin:
178	echo line 1
179	echo line 2
180	echo line 3
181	echo line 4
182	fc -l -3 -2
183expected-stdout:
184	line 1
185	line 2
186	line 3
187	line 4
188	2	echo line 2
189	3	echo line 3
190expected-stderr-pattern:
191	/^X*$/m
192---
193
194name: history-list-4
195description:
196	-1 refers to previous command
197arguments: !-i!
198env-setup: !ENV=./Env!HISTFILE=hist.file!
199file-setup: file 644 "Env"
200	PS1=X
201stdin:
202	echo line 1
203	echo line 2
204	echo line 3
205	echo line 4
206	fc -l -1 -1
207expected-stdout:
208	line 1
209	line 2
210	line 3
211	line 4
212	4	echo line 4
213expected-stderr-pattern:
214	/^X*$/m
215---
216
217name: history-list-5
218description:
219	List command stays in history
220arguments: !-i!
221env-setup: !ENV=./Env!HISTFILE=hist.file!
222file-setup: file 644 "Env"
223	PS1=X
224stdin:
225	echo line 1
226	echo line 2
227	echo line 3
228	echo line 4
229	fc -l -1 -1
230	fc -l -2 -1
231expected-stdout:
232	line 1
233	line 2
234	line 3
235	line 4
236	4	echo line 4
237	4	echo line 4
238	5	fc -l -1 -1
239expected-stderr-pattern:
240	/^X*$/m
241---
242
243name: history-list-6
244description:
245	HISTSIZE limits about of history kept.
246	(ksh88 fails 'cause it lists the fc command)
247arguments: !-i!
248env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
249file-setup: file 644 "Env"
250	PS1=X
251stdin:
252	echo line 1
253	echo line 2
254	echo line 3
255	echo line 4
256	echo line 5
257	fc -l
258expected-stdout:
259	line 1
260	line 2
261	line 3
262	line 4
263	line 5
264	4	echo line 4
265	5	echo line 5
266expected-stderr-pattern:
267	/^X*$/m
268---
269
270name: history-list-7
271description:
272	fc allows too old/new errors in range specification
273arguments: !-i!
274env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
275file-setup: file 644 "Env"
276	PS1=X
277stdin:
278	echo line 1
279	echo line 2
280	echo line 3
281	echo line 4
282	echo line 5
283	fc -l 1 30
284expected-stdout:
285	line 1
286	line 2
287	line 3
288	line 4
289	line 5
290	4	echo line 4
291	5	echo line 5
292	6	fc -l 1 30
293expected-stderr-pattern:
294	/^X*$/m
295---
296
297name: history-list-r-1
298description:
299	test -r flag in history
300arguments: !-i!
301env-setup: !ENV=./Env!HISTFILE=hist.file!
302file-setup: file 644 "Env"
303	PS1=X
304stdin:
305	echo line 1
306	echo line 2
307	echo line 3
308	echo line 4
309	echo line 5
310	fc -l -r 2 4
311expected-stdout:
312	line 1
313	line 2
314	line 3
315	line 4
316	line 5
317	4	echo line 4
318	3	echo line 3
319	2	echo line 2
320expected-stderr-pattern:
321	/^X*$/m
322---
323
324name: history-list-r-2
325description:
326	If first is newer than last, -r is implied.
327arguments: !-i!
328env-setup: !ENV=./Env!HISTFILE=hist.file!
329file-setup: file 644 "Env"
330	PS1=X
331stdin:
332	echo line 1
333	echo line 2
334	echo line 3
335	echo line 4
336	echo line 5
337	fc -l 4 2
338expected-stdout:
339	line 1
340	line 2
341	line 3
342	line 4
343	line 5
344	4	echo line 4
345	3	echo line 3
346	2	echo line 2
347expected-stderr-pattern:
348	/^X*$/m
349---
350
351name: history-list-r-3
352description:
353	If first is newer than last, -r is cancelled.
354arguments: !-i!
355env-setup: !ENV=./Env!HISTFILE=hist.file!
356file-setup: file 644 "Env"
357	PS1=X
358stdin:
359	echo line 1
360	echo line 2
361	echo line 3
362	echo line 4
363	echo line 5
364	fc -l -r 4 2
365expected-stdout:
366	line 1
367	line 2
368	line 3
369	line 4
370	line 5
371	2	echo line 2
372	3	echo line 3
373	4	echo line 4
374expected-stderr-pattern:
375	/^X*$/m
376---
377
378name: history-subst-1
379description:
380	Basic substitution
381arguments: !-i!
382env-setup: !ENV=./Env!HISTFILE=hist.file!
383file-setup: file 644 "Env"
384	PS1=X
385stdin:
386	echo abc def
387	echo ghi jkl
388	fc -e - abc=AB 'echo a'
389expected-stdout:
390	abc def
391	ghi jkl
392	AB def
393expected-stderr-pattern:
394	/^X*echo AB def\nX*$/m
395---
396
397name: history-subst-2
398description:
399	Does subst find previous command?
400arguments: !-i!
401env-setup: !ENV=./Env!HISTFILE=hist.file!
402file-setup: file 644 "Env"
403	PS1=X
404stdin:
405	echo abc def
406	echo ghi jkl
407	fc -e - jkl=XYZQRT 'echo g'
408expected-stdout:
409	abc def
410	ghi jkl
411	ghi XYZQRT
412expected-stderr-pattern:
413	/^X*echo ghi XYZQRT\nX*$/m
414---
415
416name: history-subst-3
417description:
418	Does subst find previous command when no arguments given
419arguments: !-i!
420env-setup: !ENV=./Env!HISTFILE=hist.file!
421file-setup: file 644 "Env"
422	PS1=X
423stdin:
424	echo abc def
425	echo ghi jkl
426	fc -e - jkl=XYZQRT
427expected-stdout:
428	abc def
429	ghi jkl
430	ghi XYZQRT
431expected-stderr-pattern:
432	/^X*echo ghi XYZQRT\nX*$/m
433---
434
435name: history-subst-4
436description:
437	Global substitutions work
438	(ksh88 and ksh93 do not have -g option)
439arguments: !-i!
440env-setup: !ENV=./Env!HISTFILE=hist.file!
441file-setup: file 644 "Env"
442	PS1=X
443stdin:
444	echo abc def asjj sadjhasdjh asdjhasd
445	fc -e - -g a=FooBAR
446expected-stdout:
447	abc def asjj sadjhasdjh asdjhasd
448	FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd
449expected-stderr-pattern:
450	/^X*echo FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd\nX*$/m
451---
452
453name: history-subst-5
454description:
455	Make sure searches don't find current (fc) command
456	(ksh88/ksh93 don't have the ? prefix thing so they fail this test)
457arguments: !-i!
458env-setup: !ENV=./Env!HISTFILE=hist.file!
459file-setup: file 644 "Env"
460	PS1=X
461stdin:
462	echo abc def
463	echo ghi jkl
464	fc -e - abc=AB \?abc
465expected-stdout:
466	abc def
467	ghi jkl
468	AB def
469expected-stderr-pattern:
470	/^X*echo AB def\nX*$/m
471---
472
473name: history-ed-1
474description:
475	Basic (ed) editing works (assumes you have generic ed editor
476	that prints no prompts).
477# No ed on os/2 (yet?).
478category: !os:os2
479arguments: !-i!
480env-setup: !ENV=./Env!HISTFILE=hist.file!
481file-setup: file 644 "Env"
482	PS1=X
483stdin:
484	echo abc def
485	fc echo
486	s/abc/FOOBAR/
487	w
488	q
489expected-stdout:
490	abc def
491	13
492	16
493	FOOBAR def
494expected-stderr-pattern:
495	/^X*echo FOOBAR def\nX*$/m
496---
497
498name: history-ed-2
499description:
500	Correct command is edited when number given
501category: !os:os2
502arguments: !-i!
503env-setup: !ENV=./Env!HISTFILE=hist.file!
504file-setup: file 644 "Env"
505	PS1=X
506stdin:
507	echo line 1
508	echo line 2 is here
509	echo line 3
510	echo line 4
511	fc 2
512	s/is here/is changed/
513	w
514	q
515expected-stdout:
516	line 1
517	line 2 is here
518	line 3
519	line 4
520	20
521	23
522	line 2 is changed
523expected-stderr-pattern:
524	/^X*echo line 2 is changed\nX*$/m
525---
526
527name: history-ed-3
528description:
529	Newly created multi line commands show up as single command
530	in history.
531	(NOTE: will fail if using COMPLEX HISTORY compile time option)
532	(ksh88 fails 'cause it lists the fc command)
533category: !os:os2
534arguments: !-i!
535env-setup: !ENV=./Env!HISTFILE=hist.file!
536file-setup: file 644 "Env"
537	PS1=X
538stdin:
539	echo abc def
540	fc echo
541	s/abc/FOOBAR/
542	$a
543	echo a new line
544	.
545	w
546	q
547	fc -l
548expected-stdout:
549	abc def
550	13
551	32
552	FOOBAR def
553	a new line
554	1	echo abc def
555	2	echo FOOBAR def
556		echo a new line
557expected-stderr-pattern:
558	/^X+echo FOOBAR def\necho a new line\nX*$/m
559---
560
561name: history-ignoredups-1
562description:
563	Duplicate subsequent commands are ignored.
564arguments: !-i!
565env-setup: !ENV=./Env!HISTFILE=hist.file!HISTCONTROL=ignoredups!
566file-setup: file 644 "Env"
567	PS1=X
568stdin:
569	echo a
570	echo a
571	fc -l
572expected-stdout:
573	a
574	a
575	2	echo a
576expected-stderr-pattern:
577	/^X*$/m
578---
579
580name: history-ignorespace-1
581description:
582	A command prefixed with space is discarded from history.
583arguments: !-i!
584env-setup: !ENV=./Env!HISTFILE=hist.file!HISTCONTROL=ignorespace!
585file-setup: file 644 "Env"
586	PS1=X
587stdin:
588	echo a
589	 echo b
590	fc -l
591expected-stdout:
592	a
593	b
594	2	echo a
595expected-stderr-pattern:
596	/^X*$/m
597---
598
599name: history-histcontrol-1
600description:
601	Both ignoredups and ignorespace can be specified.
602	Unrecognized and empty options are ignored.
603arguments: !-i!
604env-setup: !ENV=./Env!HISTFILE=hist.file!HISTCONTROL=ignoredups:ignorespace:foo::!
605file-setup: file 644 "Env"
606	PS1=X
607stdin:
608	echo a
609	 echo b
610	echo a
611	fc -l
612expected-stdout:
613	a
614	b
615	a
616	3	echo a
617expected-stderr-pattern:
618	/^X*$/m
619---
620
621name: history-corrupt-1
622description:
623	Every valid history line prior to a corrupted line is loaded.
624arguments: !-i!
625env-setup: !ENV=./Env!HISTFILE=hist.file!
626file-setup: !file 644 "hist.file"
627	ls
628	cd
629file-setup: file 644 "Env"
630	PS1=X
631stdin:
632	fc -l
633expected-stdout:
634	1	ls
635expected-stderr-pattern:
636	/^[^:]+: history file is corrupt\nX*$/m
637---
638
639name: history-long-lines-1
640description:
641	Long lines are ignored.
642arguments: !-i!
643env-setup: !ENV=./Env!HISTFILE=hist.file!
644file-setup: file 644 "hist.file"
645file-setup: file 644 "Env"
646	PS1=X
647perl-setup:
648	system('(echo ls; jot -b c -s "" 4096; jot -b d -s "" 4096; echo w) ' .
649		'>>hist.file');
650stdin:
651	fc -l
652expected-stdout:
653	1	ls
654	2	w
655expected-stderr-pattern:
656	/^[^:]+: ignored history line\(s\) longer than \d+ bytes\nX*$/m
657---
658