From 9ea397861feeefcce9f18947e10aa6cc155ec459 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 22 May 2018 12:43:20 -0400 Subject: Fix LoadOutputCodeCache --- deno_dir_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 deno_dir_test.go (limited to 'deno_dir_test.go') diff --git a/deno_dir_test.go b/deno_dir_test.go new file mode 100644 index 000000000..fa3d68aed --- /dev/null +++ b/deno_dir_test.go @@ -0,0 +1,46 @@ +package main + +import ( + "io/ioutil" + "testing" +) + +func SetCompileDirForTest(prefix string) { + dir, err := ioutil.TempDir("", prefix) + if err != nil { + panic(err) + } + CompileDir = dir +} + +func TestLoadOutputCodeCache(t *testing.T) { + SetCompileDirForTest("TestLoadOutputCodeCache") + + filename := "Hello.ts" + sourceCodeBuf := []byte("1+2") + + cacheFn := CacheFileName(filename, sourceCodeBuf) + + outputCode, err := LoadOutputCodeCache(filename, sourceCodeBuf) + if err != nil { + t.Fatalf(err.Error()) + } + if outputCode != "" { + t.Fatalf("Expected empty outputCode but got <<%s>>", outputCode) + } + + // Now let's write to the cache file + err = ioutil.WriteFile(cacheFn, []byte("blah"), 0700) + if err != nil { + t.Fatalf(err.Error()) + } + + // Try it again. + outputCode, err = LoadOutputCodeCache(filename, sourceCodeBuf) + if err != nil { + t.Fatalf(err.Error()) + } + if outputCode != "blah" { + t.Fatalf("Bad outputCode but got <<%s>>", outputCode) + } +} -- cgit v1.2.3