mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 04:51:22 +00:00
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
|
|
// All rights reserved. MIT License.
|
|
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"testing"
|
|
)
|
|
|
|
func SetCacheDirForTest(prefix string) {
|
|
dir, err := ioutil.TempDir("", prefix)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
CacheDir = dir
|
|
}
|
|
|
|
func TestLoadOutputCodeCache(t *testing.T) {
|
|
SetCacheDirForTest("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)
|
|
}
|
|
}
|