From aa0f5e7ee057904b200d9dcc0255396f07182296 Mon Sep 17 00:00:00 2001
From: Allan Blanchard <allan.blanchard@cea.fr>
Date: Mon, 25 Sep 2023 10:20:18 +0200
Subject: [PATCH] [tests] use dune filter for FRAMAC_SHARE in cram tests

---
 tests/syntax/cpp-command.t/filter.py |  5 -----
 tests/syntax/cpp-command.t/run.t     | 23 ++++++++++++-----------
 2 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/tests/syntax/cpp-command.t/filter.py b/tests/syntax/cpp-command.t/filter.py
index e4b379acf65..c6056c0d744 100644
--- a/tests/syntax/cpp-command.t/filter.py
+++ b/tests/syntax/cpp-command.t/filter.py
@@ -5,17 +5,12 @@
 import re
 import sys
 
-FRAMAC_SHARE = sys.argv[1]
-
 for line in sys.stdin:
     # Apply several filters:
     # - Remove preprocessed filename (randomly generated)
     line = re.sub(r"/[^ ]*cpp-command.c......\.i", "<TMPDIR/PP>.i", line)
     # - Remove hardcoded path to temporary __fc_machdepXXXXXX.dir
     line = re.sub(r"-I.*__fc_machdep......\.dir", "-I<TMP_MACHDEP>", line)
-    # - Replace occurrence of FRAMAC_SHARE; re.escape is needed if the path
-    #   contains e.g. a '+' character
-    line = re.sub(re.escape(f"-I{FRAMAC_SHARE}"), "-I<FRAMAC_SHARE>", line)
     # Remove spurious '-m32' and '-m64', which are architecture-dependent
     line = re.sub("-m32", "", line)
     line = re.sub("-m64", "", line)
diff --git a/tests/syntax/cpp-command.t/run.t b/tests/syntax/cpp-command.t/run.t
index df18a503c06..0acf9e13b4d 100644
--- a/tests/syntax/cpp-command.t/run.t
+++ b/tests/syntax/cpp-command.t/run.t
@@ -1,26 +1,27 @@
-  $ FRAMAC_SHARE="$(frama-c-config -print-share-path)"
+  $ export FRAMAC_SHARE="$(frama-c-config -print-share-path)"
+  $ export BUILD_PATH_PREFIX_MAP="\$FRAMAC_SHARE=${FRAMAC_SHARE}:$BUILD_PATH_PREFIX_MAP"
 
-  $ frama-c -check -no-autoload-plugins cpp-command.c -machdep x86_32 -cpp-frama-c-compliant -cpp-command "echo [\$(basename '%1') \$(basename '%1') \$(basename '%i') \$(basename '%input')] ['%2' '%2' '%o' '%output'] ['%args']" | python3 filter.py "$FRAMAC_SHARE"
+  $ frama-c -check -no-autoload-plugins cpp-command.c -machdep x86_32 -cpp-frama-c-compliant -cpp-command "echo [\$(basename '%1') \$(basename '%1') \$(basename '%i') \$(basename '%input')] ['%2' '%2' '%o' '%output'] ['%args']" | python3 filter.py
   [kernel] Parsing cpp-command.c (with preprocessing)
-  [cpp-command.c cpp-command.c cpp-command.c cpp-command.c] [<TMPDIR/PP>.i <TMPDIR/PP>.i <TMPDIR/PP>.i <TMPDIR/PP>.i] [-I<TMP_MACHDEP> -I<FRAMAC_SHARE>/libc -D__FRAMAC__ -dD -nostdinc]
+  [cpp-command.c cpp-command.c cpp-command.c cpp-command.c] [<TMPDIR/PP>.i <TMPDIR/PP>.i <TMPDIR/PP>.i <TMPDIR/PP>.i] [-I<TMP_MACHDEP> -I$FRAMAC_SHARE/libc -D__FRAMAC__ -dD -nostdinc]
 
-  $ frama-c -check -no-autoload-plugins cpp-command.c -machdep x86_32 -cpp-frama-c-compliant -cpp-command "echo %%1 = \$(basename '%1') %%2 = '%2' %%args = '%args'" | python3 filter.py "$FRAMAC_SHARE"
+  $ frama-c -check -no-autoload-plugins cpp-command.c -machdep x86_32 -cpp-frama-c-compliant -cpp-command "echo %%1 = \$(basename '%1') %%2 = '%2' %%args = '%args'" | python3 filter.py
   [kernel] Parsing cpp-command.c (with preprocessing)
-  %1 = cpp-command.c %2 = <TMPDIR/PP>.i %args = -I<TMP_MACHDEP> -I<FRAMAC_SHARE>/libc -D__FRAMAC__ -dD -nostdinc
+  %1 = cpp-command.c %2 = <TMPDIR/PP>.i %args = -I<TMP_MACHDEP> -I$FRAMAC_SHARE/libc -D__FRAMAC__ -dD -nostdinc
 
   $ frama-c -check -no-autoload-plugins cpp-command.c -machdep x86_32 -cpp-frama-c-compliant -cpp-command "printf \"%s\n\" \"using \\% has no effect : \$(basename \"\%input\")\""
   [kernel] Parsing cpp-command.c (with preprocessing)
   using \% has no effect : cpp-command.c'
 
-  $ frama-c -check -no-autoload-plugins cpp-command.c -machdep x86_32 -cpp-frama-c-compliant -cpp-command "echo %var is not an interpreted placeholder" | python3 filter.py "$FRAMAC_SHARE"
+  $ frama-c -check -no-autoload-plugins cpp-command.c -machdep x86_32 -cpp-frama-c-compliant -cpp-command "echo %var is not an interpreted placeholder" | python3 filter.py
   [kernel] Parsing cpp-command.c (with preprocessing)
   %var is not an interpreted placeholder
 
-  $ frama-c -check -no-autoload-plugins cpp-command.c -machdep x86_32 -print-cpp-commands | python3 filter.py "$FRAMAC_SHARE"
+  $ frama-c -check -no-autoload-plugins cpp-command.c -machdep x86_32 -print-cpp-commands | python3 filter.py
   [kernel] Preprocessing command:
-  gcc -E -C -I<TMP_MACHDEP> -I<FRAMAC_SHARE>/libc -D__FRAMAC__ -dD -nostdinc -Wno-builtin-macro-redefined -Wno-unknown-warning-option '$TESTCASE_ROOT/cpp-command.c' -o '<TMPDIR/PP>.i'
+  gcc -E -C -I<TMP_MACHDEP> -I$FRAMAC_SHARE/libc -D__FRAMAC__ -dD -nostdinc -Wno-builtin-macro-redefined -Wno-unknown-warning-option '$TESTCASE_ROOT/cpp-command.c' -o '<TMPDIR/PP>.i'
 
-  $ frama-c -check -no-autoload-plugins cpp-command.c -cpp-extra-args-per-file=cpp-command.c:"-DPF=\\\"cp%02d_%.3f\\\"" -cpp-extra-args="-DPF2=\\\"cp%02d_%.3f\\\"" -print | python3 filter.py "$FRAMAC_SHARE"
+  $ frama-c -check -no-autoload-plugins cpp-command.c -cpp-extra-args-per-file=cpp-command.c:"-DPF=\\\"cp%02d_%.3f\\\"" -cpp-extra-args="-DPF2=\\\"cp%02d_%.3f\\\"" -print | python3 filter.py
   [kernel] Parsing cpp-command.c (with preprocessing)
   /* Generated by Frama-C */
   #include "errno.h"
@@ -43,11 +44,11 @@
   
   
 
-  $ frama-c -check -no-autoload-plugins cpp-command.c -cpp-extra-args-per-file=cpp-command.c:"file_extra" -cpp-extra-args="global_extra" -cpp-command "echo 'extra_args: %args'" -print | python3 filter.py "$FRAMAC_SHARE"
+  $ frama-c -check -no-autoload-plugins cpp-command.c -cpp-extra-args-per-file=cpp-command.c:"file_extra" -cpp-extra-args="global_extra" -cpp-command "echo 'extra_args: %args'" -print | python3 filter.py
   [kernel] Warning: your preprocessor is not known to handle option `-nostdinc'. If preprocessing fails because of it, please add -no-cpp-frama-c-compliant option to Frama-C's command-line. If you do not want to see this warning again, explicitly use option -cpp-frama-c-compliant.
   [kernel] Warning: your preprocessor is not known to handle option `-dD'. If preprocessing fails because of it, please add -no-cpp-frama-c-compliant option to Frama-C's command-line. If you do not want to see this warning again, explicitly use option -cpp-frama-c-compliant.
   [kernel] Parsing cpp-command.c (with preprocessing)
-  extra_args: -I<TMP_MACHDEP> -I<FRAMAC_SHARE>/libc -D__FRAMAC__ -dD -nostdinc file_extra global_extra
+  extra_args: -I<TMP_MACHDEP> -I$FRAMAC_SHARE/libc -D__FRAMAC__ -dD -nostdinc file_extra global_extra
   [kernel] Warning: trying to preprocess annotation with an unknown preprocessor.
   /* Generated by Frama-C */
   
-- 
GitLab