diff --git a/d2cli/main.go b/d2cli/main.go index c68f9ef0c..a96277ce3 100644 --- a/d2cli/main.go +++ b/d2cli/main.go @@ -153,6 +153,10 @@ func Run(ctx context.Context, ms *xmain.State) (err error) { } } inputPath = filepath.Join(ms.PWD, inputPath) + d, err := os.Stat(inputPath) + if err == nil && d.IsDir() { + inputPath = filepath.Join(inputPath, "index.d2") + } outputPath = filepath.Join(ms.PWD, outputPath) match := d2themescatalog.Find(*themeFlag) diff --git a/e2etests-cli/main_test.go b/e2etests-cli/main_test.go index a49fdd32c..7a8fd1844 100644 --- a/e2etests-cli/main_test.go +++ b/e2etests-cli/main_test.go @@ -2,6 +2,7 @@ package e2etests_cli import ( "context" + "os" "path/filepath" "testing" "time" @@ -49,6 +50,39 @@ func TestCLI_E2E(t *testing.T) { assert.Testdata(t, ".png", png) }, }, + { + name: "multiboard/life", + run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) { + writeFile(t, dir, "life/index.d2", `x -> y +layers: { + core: { + belief + food + diet + } + broker: { + mortgage + realtor + } + stocks: { + TSX + NYSE + NASDAQ + } +} + +scenarios: { + why: { + y -> x + } +} +`) + err := runTestMain(t, ctx, dir, env, "life") + assert.Success(t, err) + + assert.TestdataDir(t, filepath.Join(dir, "life")) + }, + }, } ctx := context.Background() @@ -85,11 +119,18 @@ func runTestMain(tb testing.TB, ctx context.Context, dir string, env *xos.Env, a tms := testMain(dir, env, args...) tms.Start(tb, ctx) defer tms.Cleanup(tb) - return tms.Wait(ctx) + err := tms.Wait(ctx) + if err != nil { + return err + } + removeD2Files(tb, dir) + return nil } func writeFile(tb testing.TB, dir, fp, data string) { tb.Helper() + err := os.MkdirAll(filepath.Dir(filepath.Join(dir, fp)), 0755) + assert.Success(tb, err) assert.WriteFile(tb, filepath.Join(dir, fp), []byte(data), 0644) } @@ -97,3 +138,19 @@ func readFile(tb testing.TB, dir, fp string) []byte { tb.Helper() return assert.ReadFile(tb, filepath.Join(dir, fp)) } + +func removeD2Files(tb testing.TB, dir string) { + ea, err := os.ReadDir(dir) + assert.Success(tb, err) + + for _, e := range ea { + if e.IsDir() { + removeD2Files(tb, filepath.Join(dir, e.Name())) + continue + } + ext := filepath.Ext(e.Name()) + if ext == ".d2" { + assert.Remove(tb, filepath.Join(dir, e.Name())) + } + } +} diff --git a/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/index.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/index.exp.svg new file mode 100644 index 000000000..4787423c1 --- /dev/null +++ b/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/index.exp.svg @@ -0,0 +1,23 @@ +xy + + + diff --git a/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/layers/broker.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/layers/broker.exp.svg new file mode 100644 index 000000000..adaadb7a2 --- /dev/null +++ b/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/layers/broker.exp.svg @@ -0,0 +1,23 @@ +mortgagerealtor + + + diff --git a/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/layers/core.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/layers/core.exp.svg new file mode 100644 index 000000000..c3aac3445 --- /dev/null +++ b/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/layers/core.exp.svg @@ -0,0 +1,23 @@ +belieffooddiet + + + diff --git a/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/layers/stocks.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/layers/stocks.exp.svg new file mode 100644 index 000000000..bbfda5151 --- /dev/null +++ b/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/layers/stocks.exp.svg @@ -0,0 +1,23 @@ +TSXNYSENASDAQ + + + diff --git a/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/scenarios/why.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/scenarios/why.exp.svg new file mode 100644 index 000000000..e5ed30e0c --- /dev/null +++ b/e2etests-cli/testdata/TestCLI_E2E/multiboard/life/scenarios/why.exp.svg @@ -0,0 +1,23 @@ +xy + + + diff --git a/go.mod b/go.mod index fdcf380e4..a365cb60a 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 gonum.org/v1/plot v0.12.0 nhooyr.io/websocket v1.8.7 - oss.terrastruct.com/util-go v0.0.0-20230303033840-484c630faa46 + oss.terrastruct.com/util-go v0.0.0-20230303042538-fdc0536b018e ) require ( diff --git a/go.sum b/go.sum index d8c5c9272..97a072d2e 100644 --- a/go.sum +++ b/go.sum @@ -277,6 +277,6 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g= nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= -oss.terrastruct.com/util-go v0.0.0-20230303033840-484c630faa46 h1:pVcaRgqhNDXtWlsHg1cAy7BRycDiOaAEBexCFgMyUxQ= -oss.terrastruct.com/util-go v0.0.0-20230303033840-484c630faa46/go.mod h1:Fwy72FDIOOM4K8F96ScXkxHHppR1CPfUyo9+x9c1PBU= +oss.terrastruct.com/util-go v0.0.0-20230303042538-fdc0536b018e h1:twJhFNDPf1H45J9F2kDsof5lKQg7rW7/5M1waFngIHo= +oss.terrastruct.com/util-go v0.0.0-20230303042538-fdc0536b018e/go.mod h1:Fwy72FDIOOM4K8F96ScXkxHHppR1CPfUyo9+x9c1PBU= rsc.io/pdf v0.1.1 h1:k1MczvYDUvJBe93bYd7wrZLLUEcLZAuF824/I4e5Xr4=