From 1d479733bcbeb630557cd07f721d4510e989934c Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Sun, 19 Sep 2021 00:27:55 -0500 Subject: Add list command, copy for bash command, and ability to run non-directory commands anywhere --- adapters/bash/adapter.go | 32 ++++++++++++++++++++++++++++---- adapters/bash/config.go | 1 + 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'adapters/bash') diff --git a/adapters/bash/adapter.go b/adapters/bash/adapter.go index 8c7713c..cfa2032 100644 --- a/adapters/bash/adapter.go +++ b/adapters/bash/adapter.go @@ -3,13 +3,14 @@ package bash import ( "context" "errors" + "fmt" "log" "os" "os/exec" "path" "strings" "time" - "fmt" + "io/ioutil" "golang.flu0r1ne.net/planr" ) @@ -42,11 +43,34 @@ func (a *Adapter) Init(ctx planr.PipelineContext) { a.buildDir = ctx.AdapterDir } +func createTmpDir(dir string) string { + name, err := ioutil.TempDir(dir, "tmpbuild.*") + + if err != nil { + log.Fatal(err) + } + + return name +} + +func removeTmpDir(dir string) { + if err := os.RemoveAll(dir); err != nil { + log.Fatal(err) + } +} + func (adapter Adapter) Build(tcs []planr.TestCase) { } -func executeScriptedTest(builddir, testdir string, tc planr.TestCase) planr.TestResult { +func executeScriptedTest(builddir, testdir, srcdir string, tc planr.TestCase) planr.TestResult { cfg := tc.AdapterConfig().(*Config) + tmpdir := createTmpDir(builddir) + defer removeTmpDir(tmpdir) + + if err := planr.RecursiveCopyDir(srcdir, tmpdir); err != nil { + log.Fatalf("Could not copy sources: %v", err) + } + timeout := time.Duration(cfg.Timeout) * time.Millisecond ctx, cancel := context.WithTimeout(context.Background(), timeout) @@ -60,7 +84,7 @@ func executeScriptedTest(builddir, testdir string, tc planr.TestCase) planr.Test cmd := exec.CommandContext(ctx, "bash", path) - cmd.Dir = builddir + cmd.Dir = tmpdir if out, err := cmd.CombinedOutput(); err != nil { result.Status = planr.RUNTIME_FAILURE @@ -91,7 +115,7 @@ func (adapter Adapter) Evaluate(tcs []planr.TestCase) [] planr.TestResult { c := make(chan planr.TestResult, 0) for i := range tcs { go func(i int) { - c <- executeScriptedTest(adapter.buildDir, adapter.dirs.Tests(), tcs[i]) + c <- executeScriptedTest(adapter.buildDir, adapter.dirs.Tests(), adapter.dirs.Src(), tcs[i]) }(i) } diff --git a/adapters/bash/config.go b/adapters/bash/config.go index aaa405a..7e6ca3b 100644 --- a/adapters/bash/config.go +++ b/adapters/bash/config.go @@ -33,6 +33,7 @@ func (c *Config) finalize(path string) { if c.Timeout == 0 { c.Timeout = DEFAULT_TIMEOUT; } + } func finalizeConfigs(tcs []planr.TestCase) { -- cgit v1.2.3