about summary refs log tree commit diff
path: root/pkgs/test/cc-wrapper
diff options
context:
space:
mode:
authorRahul Butani <rrbutani@users.noreply.github.com>2023-05-03 16:45:21 -0500
committerRahul Butani <rrbutani@users.noreply.github.com>2023-05-03 16:45:48 -0500
commit40c914f1be018545992a5b2e3182f3b940f907ce (patch)
treed10cb6d403198ed664cf755af45bb8d7f8075926 /pkgs/test/cc-wrapper
parent53b268ad4a513decaad91d69483ac48319ed54cb (diff)
cc-wrapper-test: add tests for `--`
Diffstat (limited to 'pkgs/test/cc-wrapper')
-rw-r--r--pkgs/test/cc-wrapper/default.nix23
1 files changed, 23 insertions, 0 deletions
diff --git a/pkgs/test/cc-wrapper/default.nix b/pkgs/test/cc-wrapper/default.nix
index 6fd7d9f45db87..43e8e7a214268 100644
--- a/pkgs/test/cc-wrapper/default.nix
+++ b/pkgs/test/cc-wrapper/default.nix
@@ -13,6 +13,8 @@ in stdenv.mkDerivation {
   name = "cc-wrapper-test";
 
   buildCommand = ''
+    set -o pipefail
+
     NIX_DEBUG=1 $CC -v
     NIX_DEBUG=1 $CXX -v
 
@@ -43,6 +45,27 @@ in stdenv.mkDerivation {
       ''}
     ''}
 
+    ${# See: https://github.com/llvm/llvm-project/commit/ed1d07282cc9d8e4c25d585e03e5c8a1b6f63a74
+      # `gcc` does not support this so we gate the test on `clang`
+      lib.optionalString stdenv.cc.isClang ''
+        printf "checking whether cc-wrapper accepts -- followed by positional (file) args..." >&2
+        mkdir -p positional
+
+        # Make sure `--` is not parsed as a "non flag arg"; we should get an
+        # input file error here and *not* a linker error.
+        { ! $CC --; } |& grep -q "no input files"
+
+        # And that positional file args _must_ be files (this is just testing
+        # that we remembered to put the `--` back in the args to the compiler):
+        { ! $CC -c -- -o foo ${./foo.c}; } \
+          |& grep -q "no such file or directory: '-o'"
+
+        # Now check that we accept single and multiple positional file args:
+        $CC -c -DVALUE=42 -o positional/foo.o -- ${./foo.c}
+        $CC -o positional/main -- positional/foo.o ${./ldflags-main.c}
+        ${emulator} ./positional/main
+    ''}
+
     printf "checking whether compiler uses NIX_CFLAGS_COMPILE... " >&2
     mkdir -p foo/include
     cp ${./foo.c} foo/include/foo.h