github.com/ericwq/aprilsh@v0.0.0-20240517091432-958bc568daa0/frontend/signal_darwin_test.go (about)

     1  // Copyright 2022~2023 wangqi. All rights reserved.
     2  // Use of this source code is governed by a MIT-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package frontend
     6  
     7  import (
     8  	"os"
     9  	"syscall"
    10  	"testing"
    11  )
    12  
    13  /*
    14  darwin does not has the following const
    15  
    16  	syscall.SIGCLD
    17  	syscall.SIGPOLL
    18  	syscall.SIGPWR
    19  	syscall.SIGSTKFLT
    20  	syscall.SIGUNUSED
    21  */
    22  func TestGotSignal(t *testing.T) {
    23  	tc := []os.Signal{
    24  		syscall.SIGABRT, syscall.SIGALRM, syscall.SIGBUS, syscall.SIGCHLD,
    25  		syscall.SIGCONT, syscall.SIGFPE, syscall.SIGHUP, syscall.SIGILL, syscall.SIGINT,
    26  		syscall.SIGIO, syscall.SIGIOT, syscall.SIGKILL, syscall.SIGPIPE,
    27  		syscall.SIGPROF, syscall.SIGQUIT, syscall.SIGSEGV,
    28  		syscall.SIGSTOP, syscall.SIGSYS, syscall.SIGTERM, syscall.SIGTRAP, syscall.SIGTSTP,
    29  		syscall.SIGTTIN, syscall.SIGTTOU, syscall.SIGURG, syscall.SIGUSR1,
    30  		syscall.SIGUSR2, syscall.SIGVTALRM, syscall.SIGWINCH, syscall.SIGXCPU, syscall.SIGXFSZ,
    31  	}
    32  
    33  	/*
    34  	   syscall.SIGIOT and syscall.SIGABRT has conflict value
    35  	*/
    36  	result := []bool{
    37  		true, true, true, true,
    38  		true, true, true, true, true,
    39  		true, false, true, true,
    40  		true, true, true,
    41  		true, true, true, true, true,
    42  		true, true, true, true,
    43  		true, true, true, true, true,
    44  	}
    45  
    46  	// initialize Signals array
    47  	var s Signals
    48  	for i := range tc {
    49  		s.Handler(tc[i])
    50  	}
    51  
    52  	// validate GotSignal()
    53  	for i := range tc {
    54  		ss := tc[i].(syscall.Signal)
    55  		got := s.GotSignal(ss)
    56  		if got != result[i] {
    57  			t.Errorf("#test GotSignal() %q %x expect %t, got %t\n", tc[i], int(ss), result[i], got)
    58  		}
    59  	}
    60  }