scalar: create test infrastructure

To test the Scalar command, create a test script in contrib/scalar/t that is executed as `make -C contrib/scalar test`. Since Scalar has no meaningful capabilities yet, the only test is rather simple. We will add more tests in subsequent commits that introduce corresponding, new functionality. Note: This test script is intended to test `scalar` only lightly, even after all of the functionality is implemented. A more comprehensive functional (or: integration) test suite can be found at https://github.com/microsoft/scalar; It is used in the workflow https://github.com/microsoft/git/blob/HEAD/.github/workflows/scalar-functional-tests.yml in Microsoft's Git fork. This test suite performs end-to-end tests with a real remote repository, and is run as part of the regular CI and PR builds in that fork. Since those tests require some functionality supported only by Microsoft's Git fork ("GVFS protocol"), there is no intention to port that fuller test suite to `contrib/scalar/`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Dec 3, 2021 at 13:34 UTC 9187659f9a73897ba13e98fb5f08509e1ad8a713
3 files changed +109 -3
contrib/scalar/Makefile
+14 -3
@@ -3,6 +3,7 @@ QUIET_SUBDIR1 =
3
4 ifneq ($(findstring s,$(MAKEFLAGS)),s)
5 ifndef V
6 + QUIET_GEN = @echo ' ' GEN $@;
7 QUIET_SUBDIR0 = +@subdir=
8 QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
9 $(MAKE) $(PRINT_DIR) -C $$subdir
@@ -20,7 +21,7 @@ include ../../config.mak.uname
21 TARGETS = scalar$(X) scalar.o
22 GITLIBS = ../../common-main.o ../../libgit.a ../../xdiff/lib.a
23
23 -all: scalar$(X)
24 +all: scalar$(X) ../../bin-wrappers/scalar
25
26 $(GITLIBS):
27 $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(subst ../../,,$@)
@@ -29,6 +30,16 @@ $(TARGETS): $(GITLIBS) scalar.c
30 $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(patsubst %,contrib/scalar/%,$@)
31
32 clean:
32 - $(RM) $(TARGETS)
33 + $(RM) $(TARGETS) ../../bin-wrappers/scalar
34
34 -.PHONY: $(GITLIBS) all clean FORCE
35 +../../bin-wrappers/scalar: ../../wrap-for-bin.sh Makefile
36 + @mkdir -p ../../bin-wrappers
37 + $(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
38 + -e 's|@@BUILD_DIR@@|$(shell cd ../.. && pwd)|' \
39 + -e 's|@@PROG@@|contrib/scalar/scalar$(X)|' < $< > $@ && \
40 + chmod +x $@
41 +
42 +test: all
43 + $(MAKE) -C t
44 +
45 +.PHONY: $(GITLIBS) all clean test FORCE
contrib/scalar/t/Makefile new
+78
@@ -0,0 +1,78 @@
1 +# Run scalar tests
2 +#
3 +# Copyright (c) 2005,2021 Junio C Hamano, Johannes Schindelin
4 +#
5 +
6 +-include ../../../config.mak.autogen
7 +-include ../../../config.mak
8 +
9 +SHELL_PATH ?= $(SHELL)
10 +PERL_PATH ?= /usr/bin/perl
11 +RM ?= rm -f
12 +PROVE ?= prove
13 +DEFAULT_TEST_TARGET ?= test
14 +TEST_LINT ?= test-lint
15 +
16 +ifdef TEST_OUTPUT_DIRECTORY
17 +TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results
18 +else
19 +TEST_RESULTS_DIRECTORY = ../../../t/test-results
20 +endif
21 +
22 +# Shell quote;
23 +SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
24 +PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
25 +TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY))
26 +
27 +T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh))
28 +
29 +all: $(DEFAULT_TEST_TARGET)
30 +
31 +test: $(TEST_LINT)
32 + $(MAKE) aggregate-results-and-cleanup
33 +
34 +prove: $(TEST_LINT)
35 + @echo "*** prove ***"; GIT_CONFIG=.git/config $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
36 + $(MAKE) clean-except-prove-cache
37 +
38 +$(T):
39 + @echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
40 +
41 +clean-except-prove-cache:
42 + $(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)'
43 + $(RM) -r valgrind/bin
44 +
45 +clean: clean-except-prove-cache
46 + $(RM) .prove
47 +
48 +test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax
49 +
50 +test-lint-duplicates:
51 + @dups=`echo $(T) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
52 + test -z "$$dups" || { \
53 + echo >&2 "duplicate test numbers:" $$dups; exit 1; }
54 +
55 +test-lint-executable:
56 + @bad=`for i in $(T); do test -x "$$i" || echo $$i; done` && \
57 + test -z "$$bad" || { \
58 + echo >&2 "non-executable tests:" $$bad; exit 1; }
59 +
60 +test-lint-shell-syntax:
61 + @'$(PERL_PATH_SQ)' ../../../t/check-non-portable-shell.pl $(T)
62 +
63 +aggregate-results-and-cleanup: $(T)
64 + $(MAKE) aggregate-results
65 + $(MAKE) clean
66 +
67 +aggregate-results:
68 + for f in '$(TEST_RESULTS_DIRECTORY_SQ)'/t*-*.counts; do \
69 + echo "$$f"; \
70 + done | '$(SHELL_PATH_SQ)' ../../../t/aggregate-results.sh
71 +
72 +valgrind:
73 + $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind"
74 +
75 +test-results:
76 + mkdir -p test-results
77 +
78 +.PHONY: $(T) aggregate-results clean valgrind
contrib/scalar/t/t9099-scalar.sh new
+17
@@ -0,0 +1,17 @@
1 +#!/bin/sh
2 +
3 +test_description='test the `scalar` command'
4 +
5 +TEST_DIRECTORY=$PWD/../../../t
6 +export TEST_DIRECTORY
7 +
8 +# Make it work with --no-bin-wrappers
9 +PATH=$PWD/..:$PATH
10 +
11 +. ../../../t/test-lib.sh
12 +
13 +test_expect_success 'scalar shows a usage' '
14 + test_expect_code 129 scalar -h
15 +'
16 +
17 +test_done