check.go 927 字节
Newer Older
aaronchen2k2k's avatar
aaronchen2k2k 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
package biz

import (
	"fmt"
	"regexp"
	"strings"
	"utils"
)

func CheckResults(dir string, langType string) {
	scriptFiles, _ := utils.GetAllFiles(dir, langType)

	for _, scriptFile := range scriptFiles {
		logFile := utils.ScriptToLog(scriptFile)

		expectContent := utils.ReadExpect(scriptFile)
		logContent := utils.ReadFile(logFile)

		expectContent = strings.Trim(expectContent, "\n")
		logContent = strings.Trim(logContent, "\n")

		fmt.Printf(scriptFile + ": " + logFile + "\n")
		Compare(expectContent, logContent)
	}
}

func Compare(expectContent string, logContent string) {
	expectArr := strings.Split(expectContent, "\n")
	logArr := strings.Split(logContent, "\n")

	fmt.Printf("%d %d \n", len(expectArr), len(logArr))

	for numb, line := range expectArr {
		log := "N/A"
		if len(logArr) > numb {
			log = logArr[numb]
		}

		pass, _ := regexp.MatchString(line, log)

		fmt.Printf("%d: %t \n", numb+1, pass)
	}
}