Exemplo n.º 1
0
func parseDecls(manifest string) ([]Declaration, error) {
	var ast AST
	if err := parser.Parse(&ast, "t.ms", strings.NewReader(manifest)); err != nil {
		return nil, err
	}

	if decls, err := resolver.Resolve(&ast); err != nil {
		return nil, err
	} else {
		return decls, nil
	}
}
Exemplo n.º 2
0
func TestConvert(t *testing.T) {
	for _, test := range convertTests {
		ast := NewAST()
		astErr := parser.Parse(ast, "test.ms", strings.NewReader(test.manifest))
		if astErr != nil {
			t.Fatal(astErr)
		}

		resolved, resolvedErr := resolver.Resolve(ast)
		if resolvedErr != nil {
			t.Log(test.manifest)
			t.Fatal(resolvedErr)
		}

		if steps, err := Convert(resolved); err != nil {
			t.Fatal(err)
		} else if !reflect.DeepEqual(steps, test.expectedSteps) {
			t.Logf("%#v", test.expectedSteps)
			t.Logf("%#v", steps)
			t.Error("For", test.manifest, "got bad steps:", steps)
		}
	}
}
Exemplo n.º 3
0
func TestConvertInvalidManifests(t *testing.T) {
	for _, test := range invalidManifests {
		ast := NewAST()
		astErr := parser.Parse(ast, "test.ms", strings.NewReader(test.manifest))
		if astErr != nil {
			t.Log(test.manifest)
			t.Fatal(astErr)
		}

		resolved, resolvedErr := resolver.Resolve(ast)
		if resolvedErr != nil {
			t.Log(test.manifest)
			t.Fatal(resolvedErr)
		}

		if _, err := Convert(resolved); err == nil {
			t.Log(test.manifest)
			t.Error("Got no error")
		} else if err.Error() != test.err {
			t.Log(test.manifest)
			t.Error("Got bad error:", err.Error())
		}
	}
}
Exemplo n.º 4
0
func main() {
	help := false
	run := false
	verbose := false
	flag.BoolVar(&help, "h", false, "Shows this message")
	flag.BoolVar(&run, "run", false, "Actually execute the manifest")
	flag.BoolVar(&verbose, "v", false, "Verbose output")

	dirName := "../testdata"
	flag.Parse()

	if help {
		showHelp()
		return
	}

	if args := flag.CommandLine.Args(); len(args) == 1 {
		dirName = args[0]
	}

	mfst := ast.NewAST()
	if err := parseDirAsASTRecursively(mfst, dirName); err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		os.Exit(1)
	}

	resolved, resolvedErr := resolver.Resolve(mfst)
	if resolvedErr != nil {
		fmt.Fprintln(os.Stderr, resolvedErr.Error())
		os.Exit(1)
	}

	reduced, reducedErr := reducer.Reduce(resolved)
	if reducedErr != nil {
		fmt.Fprintln(os.Stderr, reducedErr.Error())
		os.Exit(1)
	}

	steps, stepsErr := stepconverter.Convert(reduced)
	if stepsErr != nil {
		fmt.Fprintln(os.Stderr, stepsErr.Error())
		os.Exit(1)
	}

	planner := planner.New()
	plan, planErr := planner.Plan(steps)
	if planErr != nil {
		fmt.Fprintln(os.Stderr, planErr.Error())
		os.Exit(1)
	}

	if run {
		realExc, realExcErr := executor.New("../script")
		if realExcErr != nil {
			fmt.Fprintln(os.Stderr, realExcErr.Error())
			os.Exit(1)
		}
		if err := executor.ExecutePlan(plan, realExc); err != nil {
			fmt.Fprintln(os.Stderr, err.Error())
			os.Exit(1)
		}
	} else {
		exc := executor.DryRun(verbose)
		if err := executor.ExecutePlan(plan, exc); err != nil {
			panic(err)
		}
	}
}