Testfile
This commit is contained in:
		
							parent
							
								
									cabe08bca4
								
							
						
					
					
						commit
						f7a74dc430
					
				
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							| @ -14,6 +14,7 @@ | |||||||
| PREFIX=/usr/local | PREFIX=/usr/local | ||||||
| 
 | 
 | ||||||
| CC=cc | CC=cc | ||||||
|  | MAKE=make | ||||||
| RUSTC=rustc | RUSTC=rustc | ||||||
| 
 | 
 | ||||||
| .PHONY: all | .PHONY: all | ||||||
| @ -42,6 +43,7 @@ install: dist | |||||||
| test: build | test: build | ||||||
| 	tests/posix-compat.sh | 	tests/posix-compat.sh | ||||||
| 	$(RUSTC) --test src/getopt-rs/lib.rs -o build/test/getopt | 	$(RUSTC) --test src/getopt-rs/lib.rs -o build/test/getopt | ||||||
|  | 	$(MAKE) -f Testfile | ||||||
| 
 | 
 | ||||||
| build/o/libsysexits.rlib: build | build/o/libsysexits.rlib: build | ||||||
| 	# bandage solution until bindgen(1) gets stdin support | 	# bandage solution until bindgen(1) gets stdin support | ||||||
|  | |||||||
							
								
								
									
										74
									
								
								TESTING
									
									
									
									
									
								
							
							
						
						
									
										74
									
								
								TESTING
									
									
									
									
									
								
							| @ -1,74 +0,0 @@ | |||||||
| #!/bin/sh |  | ||||||
| 
 |  | ||||||
| ### Overview |  | ||||||
| # |  | ||||||
| # Testing is conducted with this script, in the source tree root, using the |  | ||||||
| # tests in tests/. |  | ||||||
| # |  | ||||||
| # Basically, tests follow the format: |  | ||||||
| # |  | ||||||
| # - tests/[utility].[number].test |  | ||||||
| # 	Test #[number]. This is an executable file (typically a script). |  | ||||||
| # - tests/[utility].[number].expected |  | ||||||
| # 	This is the expected standard output of test #[number]. |  | ||||||
| # |  | ||||||
| # This script runs the executable [utility].[number].test and the following |  | ||||||
| # file is written during testing: |  | ||||||
| # |  | ||||||
| # - tests/[utility].[number].output |  | ||||||
| # 	The actual standard output from test #[number]. |  | ||||||
| # |  | ||||||
| # If the actual standard output from the test differs from the expected |  | ||||||
| # standard output, the testing ends, showing the difference. |  | ||||||
| 
 |  | ||||||
| set -e |  | ||||||
| 
 |  | ||||||
| alias emit="printf '%s: %s\n' '$0' \"\$1\"" |  | ||||||
| 
 |  | ||||||
| export PATH="$PATH:./build/bin/" |  | ||||||
| 
 |  | ||||||
| if strcmp '' "$1"; then |  | ||||||
| 	printf 'Usage: %s [utilities...]\n' "$0" >&2 |  | ||||||
| 	exit 64 # sysexits.h(3) EX_USAGE |  | ||||||
| fi |  | ||||||
| 
 |  | ||||||
| ### Details |  | ||||||
| 
 |  | ||||||
| while ! strcmp '' "$1"; do # $1 refers to the given utility |  | ||||||
| 
 |  | ||||||
| # Tests are called [utility].[number].test. Tests are numbered from 1 with no |  | ||||||
| # leading zeroes in the numbers, so (for example) scrut(1)'s first three tests |  | ||||||
| # are scrut.1.test, scrut.2.test, and scrut.3.test. Tests are run sequentially |  | ||||||
| # in the numbered order. |  | ||||||
| 
 |  | ||||||
| 	i=1 |  | ||||||
| 	while scrut -e "$1.$i.test"; do # $i refers to the test number |  | ||||||
| 		emit "$1.$i.test: Running test..." |  | ||||||
| 
 |  | ||||||
| # A test is an executable file. This runs each test for given utilities |  | ||||||
| # and writes the standard output from the test to [utility].[number].output, |  | ||||||
| # then uses diff(1p) (with the "-u" option) to highlight differences between |  | ||||||
| # the actual output and the expected output, which is located at |  | ||||||
| # [utility].[number].expected. If there are no differences none are shown and |  | ||||||
| # testing continues. |  | ||||||
| 
 |  | ||||||
| 		# $1.$i.test is the same as [utility].[number].test |  | ||||||
| 		./"$1.$i.test" \ |  | ||||||
| 			| mm -o "$1.$i.output" -o - \ |  | ||||||
| 			| diff -u - "$1.$i.expected" \ |  | ||||||
| 				|| emit '$1.$i.test: Test passed.\n' |  | ||||||
| 				# "set -e" terminates on an unsuccessful exit |  | ||||||
| 
 |  | ||||||
| # The ideal output of this script is no output at all and each |  | ||||||
| # [utility].[number].output written matching its associated |  | ||||||
| # [utility].[number].expected. |  | ||||||
| 
 |  | ||||||
| 		i=$(rpn 1 "$i" +) |  | ||||||
| 	done |  | ||||||
| 
 |  | ||||||
| 	shift |  | ||||||
| done |  | ||||||
| 
 |  | ||||||
| # -- |  | ||||||
| # This work © 2024 by DTB is licensed under CC BY-SA 4.0. To view a copy of |  | ||||||
| # this license, visit <http://creativecommons.org/licenses/by-sa/4.0/> |  | ||||||
							
								
								
									
										77
									
								
								Testfile
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										77
									
								
								Testfile
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,77 @@ | |||||||
|  | # Copyright (c) 2024 DTB <trinity@trinity.moe> | ||||||
|  | # SPDX-License-Identifier: FSFAP | ||||||
|  | # | ||||||
|  | # Copying and distribution of this file, with or without modification, are | ||||||
|  | # permitted in any medium without royalty provided the copyright notice and this | ||||||
|  | # notice are preserved.  This file is offered as-is, without any warranty. | ||||||
|  | 
 | ||||||
|  | BIN = build/bin | ||||||
|  | MAKE = make -B | ||||||
|  | 
 | ||||||
|  | DEFENDANTS = dj false intcmp strcmp true | ||||||
|  | .PHONY: all $(DEFENDANTS) | ||||||
|  | all: $(DEFENDANTS) | ||||||
|  | 
 | ||||||
|  | $(BIN)/dj: | ||||||
|  | 	$(MAKE) dj | ||||||
|  | 
 | ||||||
|  | $(BIN)/false: | ||||||
|  | 	$(MAKE) false | ||||||
|  | 
 | ||||||
|  | $(BIN)/intcmp: | ||||||
|  | 	$(MAKE) intcmp | ||||||
|  | 
 | ||||||
|  | $(BIN)/strcmp | ||||||
|  | 	$(MAKE) strcmp | ||||||
|  | 
 | ||||||
|  | $(BIN)/true: | ||||||
|  | 	$(MAKE) true | ||||||
|  | 
 | ||||||
|  | dj: $(BIN)/dj $(BIN)/strcmp | ||||||
|  | 	sh -c "! $(BIN)/dj -h" | ||||||
|  | 	# This test is theoretically Linux-dependent; write(2) should return -1 on | ||||||
|  | 	# error. | ||||||
|  | 	# Right now dj(1) interprets the return value of write(2) as the amount of | ||||||
|  | 	# bytes written. This can decrement the stored quantity of bytes written, | ||||||
|  | 	# which is an int, so doesn't underflow but goes negative. dj(1) tries to | ||||||
|  | 	# again to write(2) if an error occurs in which no bytes are written, so in | ||||||
|  | 	# total two write(2)s are attempted and so the written byte quantity is -2. | ||||||
|  | 	# This is a bug and will change, but for now is at least documented. | ||||||
|  | 	sh -ec "\ | ||||||
|  | 		$(BIN)/dj -Hi /dev/zero -o /dev/full \ | ||||||
|  | 		| xargs -I out $(BIN)/strcmp '1+0 > 0+0; 1024 > -2' out" | ||||||
|  | 	# Read nothing from /dev/null, write nothing to /dev/null. | ||||||
|  | 	sh -ec "\ | ||||||
|  | 		$(BIN)/dj -Hi /dev/null -o /dev/null \ | ||||||
|  | 		| xargs -I out $(BIN)/strcmp '0+0 > 0+0; 0 > 0' out" | ||||||
|  | 
 | ||||||
|  | false: $(BIN)/false | ||||||
|  | 	sh -c "! $(BIN)/false" | ||||||
|  | 	sh -c "! $(BIN)/false -h" | ||||||
|  | 
 | ||||||
|  | intcmp: $(BIN)/intcmp | ||||||
|  | 	intcmp -e   3 3 3 | ||||||
|  | 	intcmp -g   3 2 1 | ||||||
|  | 	intcmp -l   1 2 3 | ||||||
|  | 	intcmp -ge  3 3 1 | ||||||
|  | 	intcmp -le  1 3 3 | ||||||
|  | 	intcmp -gl  1 2 3 | ||||||
|  | 	intcmp -egl 3 1 1 2 | ||||||
|  | 	sh -c "! intcmp -e   1 2 3" | ||||||
|  | 	sh -c "! intcmp -g   1 3 3" | ||||||
|  | 	sh -c "! intcmp -l   3 3 1" | ||||||
|  | 	sh -c "! intcmp -ge  1 2 3" | ||||||
|  | 	sh -c "! intcmp -le  3 2 1" | ||||||
|  | 	sh -c "! intcmp -gl  3 3 3" | ||||||
|  | 	sh -c "! intcmp -egl foo" | ||||||
|  | 
 | ||||||
|  | strcmp: $(BIN)/strcmp | ||||||
|  | 	$(BIN)/strcmp equals equals | ||||||
|  | 	sh -c "! $(BIN)/strcmp inequals equals" | ||||||
|  | 	$(BIN)/strcmp - - | ||||||
|  | 	sh -c "! $(BIN)/strcmp -h" | ||||||
|  | 	sh -c "! $(BIN)/strcmp nocmp" | ||||||
|  | 
 | ||||||
|  | true: | ||||||
|  | 	$(BIN)/true | ||||||
|  | 	$(BIN)/true -h | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user