Skip to content

Commit 10664fd

Browse files
committed
Makefile: add rudimentary tests
1 parent 7b26834 commit 10664fd

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,28 @@ install: $(BIN)
132132
install -m 755 -d $(DESTDIR)$(MANDIR)
133133
install -m 644 nsjail.1 $(DESTDIR)$(MANDIR)
134134

135+
define run_test
136+
@echo "Testing: $(1) (expecting exit code $(2))"; \
137+
($(1)); ret=$$?; \
138+
if [ "$$ret" -ne "$(2)" ]; then \
139+
echo "❌ FAIL: '$(1)' returned $$ret, expected $(2)"; \
140+
exit 1; \
141+
else \
142+
echo "✅ PASS: '$(1)' returned $$ret"; \
143+
fi
144+
endef
145+
146+
.PHONY: test
147+
test:
148+
$(call run_test, ./nsjail -q -Mo --rw --chroot / --user 99999 --group 99999 -- /bin/bash -c 'touch $(HOME)/nsjail_test && exit 77', 77)
149+
$(call run_test, ./nsjail -q -Mo --chroot / --user 99999 --group 99999 -- /bin/bash -c 'touch $(HOME)/nsjail_test || exit 77', 77)
150+
$(call run_test, rm -f $(HOME)/nsjail_test, 0)
151+
$(call run_test, ./nsjail --config configs/bash-with-fake-geteuid.cfg -q -t 1, 137)
152+
$(call run_test, ./nsjail --config configs/bash-with-fake-geteuid.json -q -t 1, 137)
153+
$(call run_test, ./nsjail --config configs/home-documents-with-xorg-no-net.cfg -q -- /bin/true, 0)
154+
$(call run_test, ./nsjail --config configs/home-documents-with-xorg-no-net.cfg -q -- /bin/false, 1)
155+
$(call run_test, ./nsjail --config configs/firefox-with-net-wayland.cfg -q -t 4, 137)
156+
135157
# Dependencies (Generated by makedepend)
136158
# DO NOT DELETE THIS LINE -- make depend depends on it.
137159

0 commit comments

Comments
 (0)