gitee.com/Aodao/i18n4go.git@v0.2.7-0.20160826202043-6224c7d27921/integration/checkup/checkup_test.go (about) 1 package checkup_test 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 8 . "github.com/maximilien/i18n4go/integration/test_helpers" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gbytes" 12 . "github.com/onsi/gomega/gexec" 13 ) 14 15 var _ = Describe("checkup", func() { 16 var ( 17 fixturesPath string 18 session *Session 19 curDir string 20 err error 21 ) 22 23 BeforeEach(func() { 24 curDir, err = os.Getwd() 25 if err != nil { 26 fmt.Println("Could not get working directory") 27 panic(err.Error()) 28 } 29 }) 30 31 AfterEach(func() { 32 err = os.Chdir(curDir) 33 if err != nil { 34 fmt.Println("Could not change back to working directory") 35 panic(err.Error()) 36 } 37 }) 38 39 Context("When there are no problems", func() { 40 BeforeEach(func() { 41 fixturesPath = filepath.Join("..", "..", "test_fixtures", "checkup", "allgood") 42 err = os.Chdir(fixturesPath) 43 Ω(err).ToNot(HaveOccurred(), "Could not change to fixtures directory") 44 45 session = Runi18n("-c", "checkup", "-v") 46 }) 47 48 It("returns 0", func() { 49 Ω(session.ExitCode()).Should(Equal(0)) 50 }) 51 52 It("prints a reassuring message", func() { 53 Ω(session).Should(Say("OK")) 54 }) 55 }) 56 57 Context("when the i18n package is fully qualified", func() { 58 BeforeEach(func() { 59 fixturesPath = filepath.Join("..", "..", "test_fixtures", "checkup", "qualified") 60 err = os.Chdir(fixturesPath) 61 Ω(err).ToNot(HaveOccurred(), "Could not change to fixtures directory") 62 63 session = Runi18n("-c", "checkup", "-v", "-q", "i18n") 64 }) 65 66 It("returns 0", func() { 67 Ω(session.ExitCode()).Should(Equal(0)) 68 }) 69 70 It("prints a reassuring message", func() { 71 session = Runi18n("-c", "checkup", "-v", "-q", "i18n") 72 Ω(session).Should(Say("OK")) 73 }) 74 }) 75 76 Context("When there are problems", func() { 77 BeforeEach(func() { 78 fixturesPath = filepath.Join("..", "..", "test_fixtures", "checkup", "notsogood") 79 err = os.Chdir(fixturesPath) 80 Ω(err).ToNot(HaveOccurred(), "Could not change to fixtures directory") 81 82 session = Runi18n("-c", "checkup", "-v") 83 }) 84 85 It("shows all inconsistent strings and returns 1", func() { 86 output := string(session.Out.Contents()) 87 88 // strings wrapped in T() in the code that don't have corresponding keys in the translation files 89 Ω(output).Should(ContainSubstring("\"Heal the world\" exists in the code, but not in en_US")) 90 91 // keys in the translations that don't have corresponding strings wrapped in T() in the code 92 Ω(output).Should(ContainSubstring("\"Make it a better place\" exists in en_US, but not in the code")) 93 94 // keys in non-english translations that don't exist in the english translation 95 Ω(output).Should(ContainSubstring("\"For you and for me\" exists in zh_CN, but not in en_US")) 96 97 // keys that exist in the english translation but are missing in non-english translations 98 Ω(output).Should(ContainSubstring("\"And the entire human race\" exists in en_US, but not in zh_CN")) 99 100 Ω(session.ExitCode()).Should(Equal(1)) 101 }) 102 }) 103 })