This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git

commit 0aac8eadfc595fdb3adad0b6d12abea59b748c8d
Author: Szymon Janc <[email protected]>
AuthorDate: Wed Oct 21 21:23:43 2026 +0200

    newt/toolchain: Add unit test for C++ linker selection
    
    Verify that the elf is linked with compiler.path.cc by default and with
    compiler.path.cpp when the build contains C++ sources, and that a
    missing compiler.path.cpp is reported.
    
    Assisted-by: Claude:claude-opus-5-5
---
 newt/toolchain/compiler_test.go | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/newt/toolchain/compiler_test.go b/newt/toolchain/compiler_test.go
index 5685f742..6c3d11d5 100644
--- a/newt/toolchain/compiler_test.go
+++ b/newt/toolchain/compiler_test.go
@@ -23,6 +23,7 @@ import (
        "os"
        "path/filepath"
        "slices"
+       "strings"
        "testing"
 
        "mynewt.apache.org/newt/newt/cfgv"
@@ -151,3 +152,31 @@ func TestReplaceVal(t *testing.T) {
                }
        }
 }
+
+// Builds with C++ sources must be linked with the C++ compiler driver so
+// that the C++ runtime libraries are linked in.
+func TestCompileBinaryCmdLinker(t *testing.T) {
+       c := newTestCompiler()
+       c.ccPath = "arm-none-eabi-gcc"
+       c.cppPath = "arm-none-eabi-g++"
+
+       cmd := c.CompileBinaryCmd("app.elf", nil, nil, nil, "")
+       if cmd[0] != c.ccPath {
+               t.Errorf("C link uses %q, expected %q", cmd[0], c.ccPath)
+       }
+
+       c.LinkCxx = true
+       cmd = c.CompileBinaryCmd("app.elf", nil, nil, nil, "")
+       if cmd[0] != c.cppPath {
+               t.Errorf("C++ link uses %q, expected %q", cmd[0], c.cppPath)
+       }
+
+       c.cppPath = ""
+       err := c.CompileBinary("app.elf", nil, nil, nil, "")
+       if err == nil {
+               t.Fatal("C++ link without compiler.path.cpp did not fail")
+       }
+       if !strings.Contains(err.Error(), "compiler.path.cpp") {
+               t.Errorf("unexpected error: %v", err)
+       }
+}

Reply via email to