diff --git a/Makefile.coq.local b/Makefile.coq.local
index f4aa7556def57a3365052f4e04db62e5cd55c7dd..5b0ccce6a965a649e6ab07cc0233b40bb87234dc 100644
--- a/Makefile.coq.local
+++ b/Makefile.coq.local
@@ -12,7 +12,8 @@ $(TESTFILES:.v=.vo): %.vo: %.v $(VFILES:.v=.vo)
 	$(HIDE)TEST="$$(basename -s .v $<)" && \
 	  TMPFILE="$$(tempfile -p test- -s "-$$TEST")" && \
 	  $(TIMER) $(COQC) $(COQDEBUG) $(TIMING_ARG) $(COQFLAGS) $(COQLIBS) $< $(TIMING_EXTRA) > "$$TMPFILE" && \
-	  diff --color=auto -u "tests/$$TEST.ref" "$$TMPFILE"
+	  (diff --color=auto -u "tests/$$TEST.ref" "$$TMPFILE" || (rm "tests/$$TEST.vo" "$$TMPFILE" && exit 1)) && \
+	  rm "$$TMPFILE"
 
 # a target, for convenience sake, to create the .ref file with the current output
 ref: $(TESTFILES:.v=.ref)