From 3bc2342303973525addf3714d3daadd3d308efec Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 24 May 2018 10:34:05 -0400 Subject: [PATCH] Add -root flag so tests can write artifacts to tmp --- deno_dir.go | 6 +++++- integration_test.go | 11 ++++++++--- main.go | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/deno_dir.go b/deno_dir.go index 5db85cf41c..49d1e06960 100644 --- a/deno_dir.go +++ b/deno_dir.go @@ -90,7 +90,11 @@ func UserHomeDir() string { } func createDirs() { - DenoDir = path.Join(UserHomeDir(), ".deno") + if *flagRoot == "" { + DenoDir = path.Join(UserHomeDir(), ".deno") + } else { + DenoDir = *flagRoot + } CacheDir = path.Join(DenoDir, "cache") err := os.MkdirAll(CacheDir, 0700) check(err) diff --git a/integration_test.go b/integration_test.go index a646c4553b..4c525544c4 100644 --- a/integration_test.go +++ b/integration_test.go @@ -45,7 +45,7 @@ func listTestFiles() []string { return out } -func CheckOutput(t *testing.T, outFile string, denoFn string) { +func checkOutput(t *testing.T, outFile string, denoFn string) { outFile = path.Join("testdata", outFile) jsFile := strings.TrimSuffix(outFile, ".out") @@ -54,7 +54,12 @@ func CheckOutput(t *testing.T, outFile string, denoFn string) { t.Fatal(err.Error()) } - cmd := exec.Command(denoFn, jsFile, "--reload") + dir, err := ioutil.TempDir("", "TestIntegration") + if err != nil { + panic(err) + } + + cmd := exec.Command(denoFn, "--root="+dir, jsFile) var out bytes.Buffer cmd.Stdout = &out err = cmd.Run() @@ -80,7 +85,7 @@ func TestIntegration(t *testing.T) { outFiles := listTestFiles() for _, outFile := range outFiles { t.Run(outFile, func(t *testing.T) { - CheckOutput(t, outFile, denoFn) + checkOutput(t, outFile, denoFn) }) } } diff --git a/main.go b/main.go index d557ab2045..c7b92f17ed 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,8 @@ var flagReload = flag.Bool("reload", false, "Reload cached remote source code.") var flagV8Options = flag.Bool("v8-options", false, "Print V8 command line options.") var flagDebug = flag.Bool("debug", false, "Enable debug output.") var flagGoProf = flag.String("goprof", "", "Write golang cpu profile to file.") +var flagRoot = flag.String("root", "", + "Where to cache compilation artifacts. Default: ~/.deno") func stringAsset(path string) string { data, err := Asset("dist/" + path)