Exemple #1
0
func main() {

	query := flag.String("q", "", "The Query to search")
	pathString := flag.String("p", ".", "The (optional) path to run gitql")
	version := flag.Bool("v", false, "The version of gitql")
	flag.Parse()

	if *version {
		// @todo refactor to dynamic value
		fmt.Println("Gitql 1.0.0")
		return
	}

	path, errFile := filepath.Abs(*pathString)

	if errFile != nil {
		panic(errFile)
	}

	parser.New(*query)
	ast, errGit := parser.AST()
	if errGit != nil {
		panic(errGit)
	}
	ast.Path = &path
	errGit = semantical.Analysis(ast)
	if errGit != nil {
		panic(errGit)
	}

	runtime.Run(ast)
}
func TestSmallerWithDate(t *testing.T) {
	parser.New("select name from commits where date > '2013-03-14 00:00:00'")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err != nil {
		t.Fatalf(err.Error())
	}
}
func TestSmallerWithInvalidConstant(t *testing.T) {
	parser.New("select name from commits where date <= 'name'")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err == nil {
		t.Fatalf("Shoud avoid smaller with no numeric")
	}
}
func TestInvalidZeroLimit(t *testing.T) {
	parser.New("select * from commits limit 0")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err == nil {
		t.Fatalf("Should not accept limit zero")
	}
}
func TestGreaterWithNoNumeric(t *testing.T) {
	parser.New("select name from commits where date > 'name'")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err == nil {
		t.Fatalf("Shoud avoid greater with no numeric")
	}
}
func TestConstantLValue(t *testing.T) {
	parser.New("select name from commits where 'name' = 'name' ")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err != nil {
		t.Fatalf(err.Error())
	}
}
func TestChooseRepetitiveFields(t *testing.T) {
	parser.New("select name, created_at, name from commits")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err == nil {
		t.Fatalf("Shoud avoid repetitive fields")
	}
}
func TestValidNullLimit(t *testing.T) {
	parser.New("select * from commits")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err != nil {
		t.Fatalf(err.Error())
	}
}
func TestInUsingNotIdRight(t *testing.T) {
	parser.New("select * from commits where 'c' in 'cc' ")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err == nil {
		t.Fatalf("Should trow error with invalid in ")
	}
}
Exemple #10
0
func main() {
	folder, errFile := filepath.Abs(*path)

	if errFile != nil {
		log.Fatalln(errFile)
	}

	parser.New(query)
	ast, errGit := parser.AST()
	if errGit != nil {
		log.Fatalln(errGit)
	}
	ast.Path = &folder
	errGit = semantical.Analysis(ast)
	if errGit != nil {
		log.Fatalln(errGit)
	}

	runtime.Run(ast)
}