[pkg-d-commits] [ldc] 37/95: Add extra diagnostics for not-found sections in config file.

Matthias Klumpp mak at moszumanska.debian.org
Thu Jul 13 20:53:58 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v1.3.0-beta1
in repository ldc.

commit a1f484b688cda49c471622d40d56fae94c473ad5
Author: Johan Engelen <jbc.engelen at gmail.com>
Date:   Fri Mar 3 21:55:53 2017 +0100

    Add extra diagnostics for not-found sections in config file.
---
 driver/configfile.d                       | 21 +++++++++++++++++----
 tests/driver/config_diag.d                | 13 +++++++++++++
 tests/driver/inputs/noswitches.conf       |  3 +++
 tests/driver/inputs/override_default.conf |  9 +++++++++
 tests/driver/inputs/section_aaa.conf      |  4 ++++
 5 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/driver/configfile.d b/driver/configfile.d
index 3c1cb70..6dca863 100644
--- a/driver/configfile.d
+++ b/driver/configfile.d
@@ -110,28 +110,41 @@ private:
 
         try
         {
-            auto settings = parseConfigFile(cfPath);
+            auto settingSections = parseConfigFile(cfPath);
 
+            bool sectionFound;
             ArraySetting secSwitches;
             ArraySetting defSwitches;
 
-            foreach (s; settings)
+            foreach (s; settingSections)
             {
                 if (s.name == dSec)
                 {
+                    sectionFound = true;
                     secSwitches = findSwitches(s);
                 }
                 else if (s.name == "default")
                 {
+                    sectionFound = true;
                     defSwitches = findSwitches(s);
                 }
             }
 
+            if (!sectionFound)
+            {
+                const dCfPath = cfPath[0 .. strlen(cfPath)];
+                if (section)
+                    throw new Exception("Could not look up section '" ~ cast(string) dSec
+                                        ~ "' nor the 'default' section in " ~ cast(string) dCfPath);
+                else
+                    throw new Exception("Could not look up 'default' section in " ~ cast(string) dCfPath);
+            }
+
             auto switches = secSwitches ? secSwitches : defSwitches;
             if (!switches)
             {
                 const dCfPath = cfPath[0 .. strlen(cfPath)];
-                throw new Exception("could not look up switches in " ~ cast(string) dCfPath);
+                throw new Exception("Could not look up switches in " ~ cast(string) dCfPath);
             }
 
             auto finalSwitches = new const(char)*[switches.vals.length];
@@ -148,7 +161,7 @@ private:
         }
         catch (Exception ex)
         {
-            fprintf(stderr, "%.*s\n", ex.msg.length, ex.msg.ptr);
+            fprintf(stderr, "Error: %.*s\n", ex.msg.length, ex.msg.ptr);
             return false;
         }
     }
diff --git a/tests/driver/config_diag.d b/tests/driver/config_diag.d
new file mode 100644
index 0000000..6edb5a7
--- /dev/null
+++ b/tests/driver/config_diag.d
@@ -0,0 +1,13 @@
+// RUN: not %ldc -conf=%S/inputs/noswitches.conf %s 2>&1 | FileCheck %s --check-prefix=NOSWITCHES
+// NOSWITCHES: Could not look up switches in {{.*}}noswitches.conf
+
+// RUN: not %ldc -conf=%S/inputs/section_aaa.conf %s 2>&1 | FileCheck %s --check-prefix=NO_SEC
+// NO_SEC: Could not look up section '{{.*}}' nor the 'default' section in {{.*}}section_aaa.conf
+
+// RUN: %ldc -conf=%S/inputs/override_default.conf -mtriple=x86-apple-windows-msvc -c -o- %s | FileCheck %s --check-prefix=OVERRIDE_DEFAULT
+// OVERRIDE_DEFAULT: LDC - the LLVM D compiler
+
+
+void foo()
+{
+}
diff --git a/tests/driver/inputs/noswitches.conf b/tests/driver/inputs/noswitches.conf
new file mode 100644
index 0000000..8afe5de
--- /dev/null
+++ b/tests/driver/inputs/noswitches.conf
@@ -0,0 +1,3 @@
+default:
+{
+};
diff --git a/tests/driver/inputs/override_default.conf b/tests/driver/inputs/override_default.conf
new file mode 100644
index 0000000..b21a736
--- /dev/null
+++ b/tests/driver/inputs/override_default.conf
@@ -0,0 +1,9 @@
+x86-apple-windows-msvc:
+{
+    switches = [ "-version" ];
+};
+
+default:
+{
+    switches = [ "" ];
+};
diff --git a/tests/driver/inputs/section_aaa.conf b/tests/driver/inputs/section_aaa.conf
new file mode 100644
index 0000000..a85b08f
--- /dev/null
+++ b/tests/driver/inputs/section_aaa.conf
@@ -0,0 +1,4 @@
+aaa:
+{
+    switches = [ "" ];
+};

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list