mirror of
				https://github.com/beego/bee.git
				synced 2025-11-04 09:23:24 +00:00 
			
		
		
		
	Merge pull request #33 from shxsun/master
modify bee test, fix some bug
This commit is contained in:
		
							
								
								
									
										2
									
								
								new.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								new.go
									
									
									
									
									
								
							@@ -108,7 +108,7 @@ func createApp(cmd *Command, args []string) {
 | 
				
			|||||||
	writetofile(path.Join(apppath, "views", "index.tpl"), indextpl)
 | 
						writetofile(path.Join(apppath, "views", "index.tpl"), indextpl)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fmt.Println(path.Join(apppath, "main.go"))
 | 
						fmt.Println(path.Join(apppath, "main.go"))
 | 
				
			||||||
	writetofile(path.Join(apppath, "main.go"), strings.Replace(maingo, "{{.Appname}}", strings.Join(strings.Split(apppath[len(appsrcpath)+1:], string(path.Separator)), string(path.Separator)), -1))
 | 
						writetofile(path.Join(apppath, "main.go"), strings.Replace(maingo, "{{.Appname}}", strings.Join(strings.Split(apppath[len(appsrcpath)+1:], string(path.Separator)), "/"), -1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	colorLog("[SUCC] New application successfully created!\n")
 | 
						colorLog("[SUCC] New application successfully created!\n")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										49
									
								
								test.go
									
									
									
									
									
								
							
							
						
						
									
										49
									
								
								test.go
									
									
									
									
									
								
							@@ -2,10 +2,9 @@ package main
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	path "path/filepath"
 | 
					 | 
				
			||||||
	"os/exec"
 | 
						"os/exec"
 | 
				
			||||||
 | 
						path "path/filepath"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
	"bytes"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var cmdTest = &Command{
 | 
					var cmdTest = &Command{
 | 
				
			||||||
@@ -18,7 +17,21 @@ func init() {
 | 
				
			|||||||
	cmdTest.Run = testApp
 | 
						cmdTest.Run = testApp
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var started= make(chan bool)
 | 
					func safePathAppend(arr []string, paths ...string) []string {
 | 
				
			||||||
 | 
						for _, path := range paths {
 | 
				
			||||||
 | 
							if pathExists(path) {
 | 
				
			||||||
 | 
								arr = append(arr, path)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return arr
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func pathExists(path string) bool {
 | 
				
			||||||
 | 
						_, err := os.Stat(path)
 | 
				
			||||||
 | 
						return err == nil || os.IsExist(err)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var started = make(chan bool)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func testApp(cmd *Command, args []string) {
 | 
					func testApp(cmd *Command, args []string) {
 | 
				
			||||||
	if len(args) != 1 {
 | 
						if len(args) != 1 {
 | 
				
			||||||
@@ -34,7 +47,7 @@ func testApp(cmd *Command, args []string) {
 | 
				
			|||||||
		colorLog("[ERRO] Fail to parse bee.json[ %s ]", err)
 | 
							colorLog("[ERRO] Fail to parse bee.json[ %s ]", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	var paths []string
 | 
						var paths []string
 | 
				
			||||||
	paths = append(paths,
 | 
						paths = safePathAppend(paths,
 | 
				
			||||||
		path.Join(crupath, conf.DirStruct.Controllers),
 | 
							path.Join(crupath, conf.DirStruct.Controllers),
 | 
				
			||||||
		path.Join(crupath, conf.DirStruct.Models),
 | 
							path.Join(crupath, conf.DirStruct.Models),
 | 
				
			||||||
		path.Join(crupath, "./")) // Current path.
 | 
							path.Join(crupath, "./")) // Current path.
 | 
				
			||||||
@@ -50,32 +63,32 @@ func testApp(cmd *Command, args []string) {
 | 
				
			|||||||
		select {
 | 
							select {
 | 
				
			||||||
		case <-started:
 | 
							case <-started:
 | 
				
			||||||
			runTest()
 | 
								runTest()
 | 
				
			||||||
			Kill()
 | 
								//Kill()
 | 
				
			||||||
			os.Exit(0)
 | 
								//os.Exit(0)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func runTest(){
 | 
					func runTest() {
 | 
				
			||||||
	colorLog("[INFO] Start testing...\n")
 | 
						colorLog("[INFO] Start testing...\n")
 | 
				
			||||||
	time.Sleep(time.Second*5)
 | 
						time.Sleep(time.Second * 1)
 | 
				
			||||||
	path, _ := os.Getwd()
 | 
						crupwd, _ := os.Getwd()
 | 
				
			||||||
	os.Chdir(path+"/tests")
 | 
						testDir := path.Join(crupwd, "tests")
 | 
				
			||||||
 | 
						if pathExists(testDir) {
 | 
				
			||||||
 | 
							os.Chdir(testDir)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var err error
 | 
						var err error
 | 
				
			||||||
	icmd := exec.Command("go", "test")
 | 
						icmd := exec.Command("go", "test")
 | 
				
			||||||
	var out,errbuffer bytes.Buffer
 | 
						icmd.Stdout = os.Stdout
 | 
				
			||||||
	icmd.Stdout = &out
 | 
						icmd.Stderr = os.Stderr
 | 
				
			||||||
	icmd.Stderr = &errbuffer
 | 
						colorLog("[TRAC] ============== Test Begin ===================\n")
 | 
				
			||||||
	colorLog("[INFO] ============== Test Begin ===================\n")
 | 
					 | 
				
			||||||
	err = icmd.Run()
 | 
						err = icmd.Run()
 | 
				
			||||||
	colorLog(out.String())
 | 
						colorLog("[TRAC] ============== Test End ===================\n")
 | 
				
			||||||
	colorLog(errbuffer.String())
 | 
					 | 
				
			||||||
	colorLog("[INFO] ============== Test End ===================\n")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		colorLog("[ERRO] ============== Test failed ===================\n")
 | 
							colorLog("[ERRO] ============== Test failed ===================\n")
 | 
				
			||||||
		colorLog("[ERRO] " ,err)
 | 
							colorLog("[ERRO] ", err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	colorLog("[SUCC] Test finish\n")
 | 
						colorLog("[SUCC] Test finish\n")
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										7
									
								
								watch.go
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								watch.go
									
									
									
									
									
								
							@@ -3,7 +3,6 @@ package main
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"github.com/howeyc/fsnotify"
 | 
						"github.com/howeyc/fsnotify"
 | 
				
			||||||
	"log"
 | 
					 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"os/exec"
 | 
						"os/exec"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
@@ -51,7 +50,7 @@ func NewWatcher(paths []string) {
 | 
				
			|||||||
					go Autobuild()
 | 
										go Autobuild()
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			case err := <-watcher.Error:
 | 
								case err := <-watcher.Error:
 | 
				
			||||||
				log.Fatal("error:", err)
 | 
									colorLog("[WARN] %s\n", err.Error()) // No need to exit here
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}()
 | 
						}()
 | 
				
			||||||
@@ -125,7 +124,7 @@ func Kill() {
 | 
				
			|||||||
			fmt.Println("Kill -> ", e)
 | 
								fmt.Println("Kill -> ", e)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}()
 | 
						}()
 | 
				
			||||||
	if cmd != nil {
 | 
						if cmd != nil && cmd.Process != nil {
 | 
				
			||||||
		cmd.Process.Kill()
 | 
							cmd.Process.Kill()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -147,7 +146,7 @@ func Start(appname string) {
 | 
				
			|||||||
	cmd.Stderr = os.Stderr
 | 
						cmd.Stderr = os.Stderr
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	go cmd.Run()
 | 
						go cmd.Run()
 | 
				
			||||||
	started<-true
 | 
						started <- true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// checkTMPFile returns true if the event was for TMP files.
 | 
					// checkTMPFile returns true if the event was for TMP files.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user