fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
b99ae291d
master
1#!/usr/bin/env python3 2from pexpect_helper import SpawnedProc 3import os 4import pexpect 5import signal 6import sys 7 8sp = SpawnedProc () 9fish_pid = sp .spawn .pid 10assert fish_pid is not None 11sp .expect_prompt () 12 13# Set up a fish_exit handler that prints a marker to stdout. 14sp .sendline ("function __test_exit --on-event fish_exit; echo SIGTERM_CLEANUP_OK; end" ) 15sp .expect_prompt () 16 17# Run a command to populate history. 18sp .sendline ("echo sigterm_history_test_%d" % fish_pid ) 19sp .expect_prompt () 20 21# Send SIGTERM. 22os .kill (fish_pid ,signal .SIGTERM ) 23 24# Try to catch the cleanup marker before EOF. 25idx = sp .spawn .expect (["SIGTERM_CLEANUP_OK" ,pexpect .EOF ],timeout = 5 ) 26if idx == 1 : 27"FAIL: fish_exit did not fire on SIGTERM (no cleanup marker in output)" ) 28sys .exit (1 ) 29 30# Drain remaining output. 31sp .spawn .expect (pexpect .EOF ,timeout = 5 ) 32sp .spawn .close () 33 34# Verify death was by signal (re-raised SIGTERM), not normal exit. 35if sp .spawn .signalstatus != signal .SIGTERM : 36"FAIL: expected SIGTERM, got signal=%s exit=%s" 38% (sp .spawn .signalstatus ,sp .spawn .exitstatus ) 39 ) 40sys .exit (1 ) 41 42# Check history file for NUL bytes. 43histfile = os .path .join (os .environ ["XDG_DATA_HOME" ],"fish" ,"fish_history" ) 44with open (histfile ,"rb" )as f : 45raw = f .read () 46assert len (raw )!= 0 ,"history file is empty" 47nul_count = raw .count (b"\x00" ) 48if nul_count > 0 : 49"FAIL: history file contains %d NUL bytes" % nul_count ) 50sys .exit (1 )