aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/print_cmdline_flag_test.go
diff options
context:
space:
mode:
authorTobias Bosch <tbosch@google.com>2019-07-11 04:24:52 -0700
committerTobias Bosch <tbosch@google.com>2019-07-13 12:29:19 +0000
commit584728183f90cf6ef27fa09b52c8ee5203c87e4a (patch)
tree4d725a5553ab177f66b86c27075935ee5827cae3 /compiler_wrapper/print_cmdline_flag_test.go
parent6652ca32cb1194acb1771121189f1531c3644402 (diff)
downloadtoolchain-utils-584728183f90cf6ef27fa09b52c8ee5203c87e4a.tar.gz
Add -print-cmdline and -print-config
BUG=chromium:773875 TEST=unit test Change-Id: Ib25e582257694f3a3457795873a249735e3aaf82 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1697931 Tested-by: Tobias Bosch <tbosch@google.com> Reviewed-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'compiler_wrapper/print_cmdline_flag_test.go')
-rw-r--r--compiler_wrapper/print_cmdline_flag_test.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/compiler_wrapper/print_cmdline_flag_test.go b/compiler_wrapper/print_cmdline_flag_test.go
new file mode 100644
index 00000000..f3ccd723
--- /dev/null
+++ b/compiler_wrapper/print_cmdline_flag_test.go
@@ -0,0 +1,81 @@
+package main
+
+import (
+ "fmt"
+ "regexp"
+ "testing"
+)
+
+func TestRemovePrintCmdlineArg(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ cmd := ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, "-print-cmdline", mainCc)))
+ if err := verifyArgCount(cmd, 0, "-print-cmdline"); err != nil {
+ t.Error(err)
+ }
+ })
+}
+
+func TestPrintCompilerCommand(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, "-print-cmdline", mainCc)))
+ if matched, _ := regexp.MatchString(`cd '.*' && '.*/x86_64-cros-linux-gnu-gcc.real'.*'main.cc'`, ctx.stderrString()); !matched {
+ t.Errorf("sub command not printed to stderr. Got: %s", ctx.stderrString())
+ }
+ })
+}
+
+func TestPrintNestedCommand(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ // Note: -clang-syntax calls clang to check the syntax
+ ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, "-print-cmdline", "-clang-syntax", mainCc)))
+ if matched, _ := regexp.MatchString(`cd '.*' && '.*usr/bin/clang'.*'main.cc'.*'-fsyntax-only'`, ctx.stderrString()); !matched {
+ t.Errorf("sub command not printed to stderr. Got: %s", ctx.stderrString())
+ }
+ })
+}
+
+func TestPrintCmdWd(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ printCmd(ctx, &command{
+ path: "/somepath",
+ })
+ if ctx.stderrString() != fmt.Sprintf("cd '%s' && '/somepath'\n", ctx.tempDir) {
+ t.Errorf("unexpected result. Got: %s", ctx.stderrString())
+ }
+ })
+}
+
+func TestPrintCmdAbsolutePath(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ printCmd(ctx, &command{
+ path: "somepath",
+ })
+ if ctx.stderrString() != fmt.Sprintf("cd '%s' && '%s/somepath'\n", ctx.tempDir, ctx.tempDir) {
+ t.Errorf("unexpected result. Got: %s", ctx.stderrString())
+ }
+ })
+}
+
+func TestPrintCmdEnvUpdates(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ printCmd(ctx, &command{
+ path: "/somepath",
+ envUpdates: []string{"a=b"},
+ })
+ if ctx.stderrString() != fmt.Sprintf("cd '%s' && env 'a=b' '/somepath'\n", ctx.tempDir) {
+ t.Errorf("unexpected result. Got: %s", ctx.stderrString())
+ }
+ })
+}
+
+func TestPrintCmdArgs(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ printCmd(ctx, &command{
+ path: "/somepath",
+ args: []string{"-a"},
+ })
+ if ctx.stderrString() != fmt.Sprintf("cd '%s' && '/somepath' '-a'\n", ctx.tempDir) {
+ t.Errorf("unexpected result. Got: %s", ctx.stderrString())
+ }
+ })
+}