From e9d5b1d9c88b2a1fd859496f2c4bb2aa7eceb75d Mon Sep 17 00:00:00 2001
From: Virgile Prevosto <virgile.prevosto@m4x.org>
Date: Wed, 1 Jul 2020 10:59:53 +0200
Subject: [PATCH] [tests] conditional run of preprocess_dos.c (only if unix2dos
 exists)

---
 .gitignore                     |  3 +++
 Makefile                       | 22 ++++++++++++++++++++--
 tests/spec/preprocess_dos.c    | 11 -----------
 tests/spec/preprocess_dos.c.in | 12 ++++++++++++
 tests/spec/preprocess_dos.sh   |  4 ++--
 5 files changed, 37 insertions(+), 15 deletions(-)
 delete mode 100644 tests/spec/preprocess_dos.c
 create mode 100644 tests/spec/preprocess_dos.c.in

diff --git a/.gitignore b/.gitignore
index 1280fb74b63..c4204e5ff6e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,6 +55,7 @@ autom4te.cache
 /tests/journal/intra.byte
 /tests/misc/my_visitor_plugin/my_visitor.opt
 /tests/misc/my_visitor.sav
+/tests/spec/preprocess_dos.c
 /tests/*/*.opt
 /tests/pdg/*.dot
 
@@ -92,6 +93,8 @@ autom4te.cache
 
 /doc/acsl/
 
+/doc/aorai/aorai-example.tgz
+/doc/aorai/aorai-example/
 /doc/aorai/frama-c-aorai-example.tgz
 /doc/aorai/frama-c-aorai-example
 /doc/aorai/main.pdf
diff --git a/Makefile b/Makefile
index d6d044aebe2..6c52c7c5523 100644
--- a/Makefile
+++ b/Makefile
@@ -2338,7 +2338,25 @@ PTESTS_SRC=ptests/ptests_config.ml ptests/ptests.ml
 # that does not contain a 'tests' dir
 PTESTS_CONFIG:= $(shell if test -d tests; then echo tests/ptests_config; fi)
 
-ptests: bin/ptests.$(OCAMLBEST)$(EXE) $(PTESTS_CONFIG)
+ifneq ("$(PTESTS_CONFIG)","")
+GENERATED_TESTS:=tests/spec/preprocess_dos.c
+else
+GENERATED_TESTS:=
+endif
+
+ifneq ("$(HAS_UNIX2DOS)","no")
+tests/spec/preprocess_dos.c: tests/spec/preprocess_dos.c.in
+	$(SED) -e "s|@UNIX2DOS@|$(UNIX2DOS)|g" \
+               -e "s|@DONTRUN@||g" \
+               $< > $@
+else
+tests/spec/preprocess_dos.c: tests/spec/preprocess_dos.c.in
+	$(SED) -e "s|@DONTRUN@|DONTRUN: no unix2dos found|g" \
+               -e "s|@UNIX2DOS|unix2dos|g" \
+               $< > $@
+endif
+
+ptests: bin/ptests.$(OCAMLBEST)$(EXE) $(PTESTS_CONFIG) $(GENERATED_TESTS)
 
 bin/ptests.byte$(EXE): $(PTESTS_SRC)
 	$(PRINT_LINKING) $@
@@ -2350,7 +2368,7 @@ bin/ptests.opt$(EXE): $(PTESTS_SRC)
 	$(OCAMLOPT) -I ptests -dtypes -thread -o $@ \
 	    unix.cmxa threads.cmxa str.cmxa dynlink.cmxa $^
 
-GENERATED+=ptests/ptests_config.ml tests/ptests_config
+GENERATED+=ptests/ptests_config.ml tests/ptests_config $(GENERATED_TESTS)
 
 #######################
 # Source distribution #
diff --git a/tests/spec/preprocess_dos.c b/tests/spec/preprocess_dos.c
deleted file mode 100644
index 959cc59c6bf..00000000000
--- a/tests/spec/preprocess_dos.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* run.config*
-OPT: -cpp-command="@PTEST_DIR@/@PTEST_NAME@.sh %i %o" -cpp-frama-c-compliant -print
-*/
-
-int main() {
-    int a = 0;
-    /*@
-        assert a == 0;
-    */
-    return a;
-}
diff --git a/tests/spec/preprocess_dos.c.in b/tests/spec/preprocess_dos.c.in
new file mode 100644
index 00000000000..e51e54c473c
--- /dev/null
+++ b/tests/spec/preprocess_dos.c.in
@@ -0,0 +1,12 @@
+/* run.config*
+@DONTRUN@
+OPT: -cpp-command="@PTEST_DIR@/@PTEST_NAME@.sh @UNIX2DOS@ %i %o" -cpp-frama-c-compliant -print
+*/
+
+int main() {
+    int a = 0;
+    /*@
+        assert a == 0;
+    */
+    return a;
+}
diff --git a/tests/spec/preprocess_dos.sh b/tests/spec/preprocess_dos.sh
index b2be8f41003..a63a982d043 100755
--- a/tests/spec/preprocess_dos.sh
+++ b/tests/spec/preprocess_dos.sh
@@ -1,3 +1,3 @@
 #!/bin/sh
-gcc -C -E -I. -o $2 $1
-dos2unix -q $2
+gcc -C -E -I. -o $3 $2
+$1 -q $3
-- 
GitLab