From 9c8701a449db79ad38ddd598359a1819341fc99b Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Tue, 6 Jun 2023 17:14:34 -0700 Subject: [PATCH] fixup! fixup! fixup! d2ir: Fix pushImportStack --- d2ir/import.go | 5 ++--- e2etests-cli/main_test.go | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/d2ir/import.go b/d2ir/import.go index 74e961943d..2a58a0622b 100644 --- a/d2ir/import.go +++ b/d2ir/import.go @@ -30,15 +30,14 @@ func (c *compiler) pushImportStack(imp *d2ast.Import) (string, bool) { impPath = path.Join(path.Dir(c.importStack[len(c.importStack)-1]), impPath) } - newPath := imp.PathWithPre() for i, p := range c.importStack { - if newPath == p { + if impPath == p { c.errorf(imp, "detected cyclic import chain: %s", formatCyclicChain(c.importStack[i:])) return "", false } } - c.importStack = append(c.importStack, newPath) + c.importStack = append(c.importStack, impPath) return impPath, true } diff --git a/e2etests-cli/main_test.go b/e2etests-cli/main_test.go index aff8d6f63f..0889f8403a 100644 --- a/e2etests-cli/main_test.go +++ b/e2etests-cli/main_test.go @@ -8,13 +8,14 @@ import ( "testing" "time" - "oss.terrastruct.com/d2/d2cli" - "oss.terrastruct.com/d2/lib/pptx" - "oss.terrastruct.com/d2/lib/xgif" "oss.terrastruct.com/util-go/assert" "oss.terrastruct.com/util-go/diff" "oss.terrastruct.com/util-go/xmain" "oss.terrastruct.com/util-go/xos" + + "oss.terrastruct.com/d2/d2cli" + "oss.terrastruct.com/d2/lib/pptx" + "oss.terrastruct.com/d2/lib/xgif" ) func TestCLI_E2E(t *testing.T) { @@ -389,6 +390,18 @@ steps: { assert.Testdata(t, ".svg", svg) }, }, + { + name: "chain_import", + run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) { + writeFile(t, dir, "hello-world.d2", `...@x`) + writeFile(t, dir, "x.d2", `...@y`) + writeFile(t, dir, "y.d2", `meow`) + err := runTestMain(t, ctx, dir, env, filepath.Join(dir, "hello-world.d2")) + assert.Success(t, err) + svg := readFile(t, dir, "hello-world.svg") + assert.Testdata(t, ".svg", svg) + }, + }, } ctx := context.Background()