Skip to content

Commit

Permalink
fixup! fixup! fixup! d2ir: Fix pushImportStack
Browse files Browse the repository at this point in the history
  • Loading branch information
nhooyr committed Jun 7, 2023
1 parent ca8c594 commit 9c8701a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
5 changes: 2 additions & 3 deletions d2ir/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
19 changes: 16 additions & 3 deletions e2etests-cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 9c8701a

Please sign in to comment.