github.com/ericwq/aprilsh@v0.0.0-20240517091432-958bc568daa0/frontend/signal_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  	"syscall"
     9  	"testing"
    10  )
    11  
    12  func TestAnySignal(t *testing.T) {
    13  	var s Signals
    14  
    15  	s.Handler(syscall.Signal(-1))
    16  	if s.AnySignal() {
    17  		t.Errorf("#test AnySignal() expect false got %t", s.AnySignal())
    18  	}
    19  
    20  	s.Handler(syscall.SIGABRT)
    21  	if !s.AnySignal() {
    22  		t.Errorf("#test AnySignal() expect true got %t", s.AnySignal())
    23  	}
    24  }
    25  
    26  func TestClear(t *testing.T) {
    27  	var s Signals
    28  
    29  	s.Handler(syscall.SIGTERM)
    30  	s.Handler(syscall.SIGINT)
    31  	s.Handler(syscall.SIGHUP)
    32  
    33  	if !s.AnySignal() {
    34  		t.Errorf("#test AnySignal() expect true, got %t\n", s.AnySignal())
    35  	}
    36  
    37  	s.Clear()
    38  
    39  	if s.AnySignal() {
    40  		t.Errorf("#test AnySignal() expect false, got %t\n", s.AnySignal())
    41  	}
    42  }