path_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2013 com authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License"): you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. // License for the specific language governing permissions and limitations
  13. // under the License.
  14. package com
  15. import (
  16. "os"
  17. "runtime"
  18. "testing"
  19. )
  20. func TestGetGOPATHs(t *testing.T) {
  21. var gpsR []string
  22. if runtime.GOOS != "windows" {
  23. gpsR = []string{"path/to/gopath1", "path/to/gopath2", "path/to/gopath3"}
  24. os.Setenv("GOPATH", "path/to/gopath1:path/to/gopath2:path/to/gopath3")
  25. } else {
  26. gpsR = []string{"path/to/gopath1", "path/to/gopath2", "path/to/gopath3"}
  27. os.Setenv("GOPATH", "path\\to\\gopath1;path\\to\\gopath2;path\\to\\gopath3")
  28. }
  29. gps := GetGOPATHs()
  30. if !CompareSliceStr(gps, gpsR) {
  31. t.Errorf("GetGOPATHs:\n Expect => %s\n Got => %s\n", gpsR, gps)
  32. }
  33. }
  34. func TestGetSrcPath(t *testing.T) {
  35. }
  36. func TestHomeDir(t *testing.T) {
  37. _, err := HomeDir()
  38. if err != nil {
  39. t.Errorf("HomeDir:\n Expect => %v\n Got => %s\n", nil, err)
  40. }
  41. }
  42. func BenchmarkGetGOPATHs(b *testing.B) {
  43. for i := 0; i < b.N; i++ {
  44. GetGOPATHs()
  45. }
  46. }
  47. func BenchmarkGetSrcPath(b *testing.B) {
  48. for i := 0; i < b.N; i++ {
  49. GetSrcPath("notabug.org/makenotabuggreatagain/com")
  50. }
  51. }
  52. func BenchmarkHomeDir(b *testing.B) {
  53. for i := 0; i < b.N; i++ {
  54. HomeDir()
  55. }
  56. }