github.com/haagen/force@v0.19.6-0.20140911230915-22addd930b34/test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "strconv" 6 ) 7 8 var cmdTest = &Command{ 9 Usage: "test (all | classname...)", 10 Short: "Run apex tests", 11 Long: ` 12 Run apex tests 13 14 Test Options 15 -namespace=<namespace> Select namespace to run test from 16 17 Examples: 18 19 force test all 20 force test Test1 Test2 Test3 21 force test -namespace=ns Test4 22 `, 23 } 24 25 func init() { 26 cmdTest.Run = runTests 27 } 28 29 var ( 30 namespaceTestFlag = cmdTest.Flag.String("namespace", "", "namespace to run tests in") 31 ) 32 33 func runTests(cmd *Command, args []string) { 34 if len(args) < 1 { 35 ErrorAndExit("must specify tests to run") 36 } 37 force, _ := ActiveForce() 38 output, err := force.Partner.RunTests(args, *namespaceTestFlag) 39 success := false 40 if err != nil { 41 ErrorAndExit(err.Error()) 42 } else { 43 //working on a better way to do this - catches when no class are found and ran 44 if output.NumberRun == 0 { 45 fmt.Println("Test classes specified not found") 46 } else { 47 var percent string 48 fmt.Println("Coverage:") 49 fmt.Println() 50 for index := range output.NumberLocations { 51 if output.NumberLocations[index] != 0 { 52 percent = strconv.Itoa(((output.NumberLocations[index]-output.NumberLocationsNotCovered[index])/output.NumberLocations[index])*100) + "%" 53 } else { 54 percent = "0%" 55 } 56 fmt.Println(" " + percent + " " + output.Name[index]) 57 } 58 fmt.Println() 59 fmt.Println() 60 fmt.Println("Results:") 61 fmt.Println() 62 for index := range output.SMethodNames { 63 fmt.Println(" [PASS] " + output.SClassNames[index] + "::" + output.SMethodNames[index]) 64 } 65 66 for index := range output.FMethodNames { 67 fmt.Println(" [FAIL] " + output.FClassNames[index] + "::" + output.FMethodNames[index] + ": " + output.FMessage[index]) 68 fmt.Println(" " + output.FStackTrace[index]) 69 } 70 fmt.Println() 71 fmt.Println() 72 73 success = len(output.FMethodNames) == 0 74 } 75 76 // Handle notifications 77 notifySuccess("test", success) 78 } 79 }