hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

signal_test.ha (1745B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 // Test sigset operations do not fail for valid signal numbers.
      5 @test fn sigset_valid_signum() void = {
      6 	let set = sigset { ... };
      7 	sigemptyset(&set);
      8 
      9 	assert(!(sigismember(&set, 1) is errno), "Unexpected error");
     10 	assert(!(sigismember(&set, 15) is errno), "Unexpected error");
     11 	assert(!(sigismember(&set, NSIG) is errno), "Unexpected error");
     12 
     13 	assert(!(sigaddset(&set, 1) is errno), "Unexpected error");
     14 	assert(!(sigaddset(&set, 15) is errno), "Unexpected error");
     15 	assert(!(sigaddset(&set, NSIG) is errno), "Unexpected error");
     16 
     17 	// It's ok to add a signal that is already present in the set.
     18 	assert(!(sigaddset(&set, 1) is errno), "Unexpected error");
     19 
     20 	assert(!(sigdelset(&set, 1) is errno), "Unexpected error");
     21 	assert(!(sigdelset(&set, 15) is errno), "Unexpected error");
     22 	assert(!(sigdelset(&set, NSIG) is errno), "Unexpected error");
     23 
     24 	// It's ok to delete a signal that is not present in the set.
     25 	assert(!(sigdelset(&set, 10) is errno), "Unexpected error");
     26 };
     27 
     28 // Test sigset operations fail for invalid signal numbers.
     29 @test fn sigset_invalid_signum() void = {
     30 	let set = sigset { ... };
     31 	sigemptyset(&set);
     32 
     33 	assert(sigismember(&set, -1) is errno, "Expected error");
     34 	assert(sigismember(&set, 0) is errno, "Expected error");
     35 	assert(sigismember(&set, NSIG + 1) is errno, "Expected error");
     36 
     37 	assert(sigaddset(&set, -1) is errno, "Expected error");
     38 	assert(sigaddset(&set, 0) is errno, "Expected error");
     39 	assert(sigaddset(&set, NSIG + 1) is errno, "Expected error");
     40 
     41 	assert(sigdelset(&set, -1) is errno, "Expected error");
     42 	assert(sigdelset(&set, 0) is errno, "Expected error");
     43 	assert(sigdelset(&set, NSIG + 1) is errno, "Expected error");
     44 };