aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/testing/testing_test.go
diff options
context:
space:
mode:
authorGiuliano Belinassi <giuliano.belinassi@usp.br>2020-08-22 17:43:43 -0300
committerGiuliano Belinassi <giuliano.belinassi@usp.br>2020-08-22 17:43:43 -0300
commita926878ddbd5a98b272c22171ce58663fc04c3e0 (patch)
tree86af256e5d9a9c06263c00adc90e5fe348008c43 /libgo/go/testing/testing_test.go
parent542730f087133690b47e036dfd43eb0db8a650ce (diff)
parent07cbaed8ba7d1b6e4ab3a9f44175502a4e1ecdb1 (diff)
downloadgcc-devel/autopar_devel.zip
gcc-devel/autopar_devel.tar.gz
gcc-devel/autopar_devel.tar.bz2
Merge branch 'autopar_rebase2' into autopar_develdevel/autopar_devel
Quickly commit changes in the rebase branch.
Diffstat (limited to 'libgo/go/testing/testing_test.go')
-rw-r--r--libgo/go/testing/testing_test.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/libgo/go/testing/testing_test.go b/libgo/go/testing/testing_test.go
index 45e4468..dbef706 100644
--- a/libgo/go/testing/testing_test.go
+++ b/libgo/go/testing/testing_test.go
@@ -5,7 +5,9 @@
package testing_test
import (
+ "io/ioutil"
"os"
+ "path/filepath"
"testing"
)
@@ -16,3 +18,63 @@ import (
func TestMain(m *testing.M) {
os.Exit(m.Run())
}
+
+func TestTempDir(t *testing.T) {
+ testTempDir(t)
+ t.Run("InSubtest", testTempDir)
+ t.Run("test/subtest", testTempDir)
+ t.Run("test\\subtest", testTempDir)
+ t.Run("test:subtest", testTempDir)
+ t.Run("test/..", testTempDir)
+ t.Run("../test", testTempDir)
+}
+
+func testTempDir(t *testing.T) {
+ dirCh := make(chan string, 1)
+ t.Cleanup(func() {
+ // Verify directory has been removed.
+ select {
+ case dir := <-dirCh:
+ fi, err := os.Stat(dir)
+ if os.IsNotExist(err) {
+ // All good
+ return
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Errorf("directory %q stil exists: %v, isDir=%v", dir, fi, fi.IsDir())
+ default:
+ if !t.Failed() {
+ t.Fatal("never received dir channel")
+ }
+ }
+ })
+
+ dir := t.TempDir()
+ if dir == "" {
+ t.Fatal("expected dir")
+ }
+ dir2 := t.TempDir()
+ if dir == dir2 {
+ t.Fatal("subsequent calls to TempDir returned the same directory")
+ }
+ if filepath.Dir(dir) != filepath.Dir(dir2) {
+ t.Fatalf("calls to TempDir do not share a parent; got %q, %q", dir, dir2)
+ }
+ dirCh <- dir
+ fi, err := os.Stat(dir)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !fi.IsDir() {
+ t.Errorf("dir %q is not a dir", dir)
+ }
+ fis, err := ioutil.ReadDir(dir)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(fis) > 0 {
+ t.Errorf("unexpected %d files in TempDir: %v", len(fis), fis)
+ }
+}