Exemple #1
0
func NewTritiumTestFromFolder(path string) (test *TritiumTest, err error) {
	script, err := ioutil.ReadFile(filepath.Join(path, "input.ts"))
	if err != nil {
		script = []byte("")
	}

	input, err := ioutil.ReadFile(filepath.Join(path, "input.http"))
	if err != nil {
		input = []byte("")
	}

	output, err := ioutil.ReadFile(filepath.Join(path, "output.http"))
	if err != nil {
		output = []byte("")
	}

	env := make(map[string]string, 0)
	data, err := ioutil.ReadFile(filepath.Join(path, "vars.yml"))
	if err == nil {
		err = yaml.Unmarshal(data, &env)
		if err != nil {
			return
		}
	}

	exports := make([][]string, 0)
	data, err = ioutil.ReadFile(filepath.Join(path, "exports.yml"))
	if err == nil {
		err = yaml.Unmarshal(data, &exports)
		if err != nil {
			return
		}
	}

	test = &TritiumTest{
		Script: string(script),
		Input:  string(input),
		Output: string(output),
		Logs:   []string{},
	}

	test.SetEnv(env)
	test.SetExports(exports)

	return test, nil
}
Exemple #2
0
func read_test_cases(test_file string) (ProjectTests, error) {
	tests := ProjectTests{}
	fileinfo, err := ioutil.ReadFile(test_file)
	if err != nil {
		return tests, err
	}
	err = goyaml.Unmarshal([]byte(fileinfo), &tests)
	return tests, err
}
Exemple #3
0
func loadExports(dir string) [][]string {
	data := []byte(loadFile(dir, "exports.yml"))
	exports := make([][]string, 0)
	err := yaml.Unmarshal(data, &exports)
	if err != nil {
		log.Panic(err)
	}
	return exports
}
Exemple #4
0
func loadVars(dir string) map[string]string {
	data := []byte(loadFile(dir, "vars.yml"))
	vars := make(map[string]string, 0)
	err := yaml.Unmarshal(data, &vars)
	if err != nil {
		log.Panic(err)
	}
	return vars
}
Exemple #5
0
func loadLogs(dir string) []string {
	data := []byte(loadFile(dir, "logs.yml"))
	logs := make([]string, 0)
	err := yaml.Unmarshal(data, &logs)
	if err != nil {
		log.Panic(err)
	}
	return logs
}
Exemple #6
0
// Not fully functional. Dang it.
func ReadPackageInfoFile(location string) (info *PackageInfo, error *string) {
	//	println("READING PACKAGE INFO FILE", location + "/package.yml")
	packageInfo := &PackageInfo{}
	infoFile, err := ioutil.ReadFile(location + "/package.yml")
	if err != nil {
		message := "No package info file found at " + location + "/package.yml"
		return nil, &message
	}
	yaml.Unmarshal([]byte(infoFile), &packageInfo)
	//fmt.Printf("--- m:\n%v\n\n", packageInfo)
	return packageInfo, nil
}
Exemple #7
0
func (pkgr *Packager) readDependenciesFile() {
	depPath := filepath.Join(pkgr.MixerDir, DEPS_FILE)
	depPathExists, _ := fileutil.Exists(depPath)
	if !depPathExists {
		return
	}
	data, readErr := ioutil.ReadFile(filepath.Join(pkgr.MixerDir, DEPS_FILE))
	if readErr != nil {
		panic(fmt.Sprintf("error reading dependencies file for `%s`", pkgr.Mixer.GetName()))
	}
	pkgr.Dependencies = make(map[string]string)
	yaml.Unmarshal(data, &pkgr.Dependencies)
}
Exemple #8
0
func (m *Mixer) loadDependentMixers() {

	data, err := ioutil.ReadFile(filepath.Join(m.DefinitionPath, "/dependencies.yml"))

	if err != nil {
		// No dependencies
		return
	}

	dependencies := make(map[string]string)
	yaml.Unmarshal(data, &dependencies)

	for fullName, _ := range dependencies {
		m.loadDependentMixer(m.LibraryPath, fullName)
	}

}
Exemple #9
0
func (pkgr *Packager) resolveTypeDeclarations() {
	// see whether a type declarations file exists; if so, read it
	typeFilePath := filepath.Join(pkgr.MixerDir, pkgr.LibDir, TYPES_FILE)
	there, _ := fileutil.Exists(typeFilePath)
	if !there {
		return
	}
	data, readErr := ioutil.ReadFile(typeFilePath)
	if readErr != nil {
		panic(fmt.Sprintf("error reading type declarations file for `%s`", pkgr.Mixer.GetName()))
	}
	typeDecs := make([]string, 0)
	yaml.Unmarshal(data, &typeDecs)
	if pkgr.TypeMap == nil {
		pkgr.TypeMap = make(map[string]int)
	}
	if pkgr.SuperclassOf == nil {
		pkgr.SuperclassOf = make(map[string]string)
	}

	// now resolve the type declarations
	for _, typeDec := range typeDecs {
		// TODO: this logic is more complicated than it needs to be. Should really
		// just disallow any duplicate declarations. Anyway....

		// if the type doesn't extend anything ...
		if !strings.Contains(typeDec, "<") {
			_, isThere := pkgr.TypeMap[typeDec]
			if !isThere {
				pkgr.TypeMap[typeDec] = len(pkgr.TypeMap)
				pkgr.SuperclassOf[typeDec] = ""
				// if the type has already been declared, check for a semantic conflict
			} else if extendee := pkgr.SuperclassOf[typeDec]; extendee != "" {
				panic(fmt.Sprintf("type declaration `%s` conflicts with previous declaration `%s < %s`", typeDec, typeDec, extendee))
			}
			// if we get to this point, the declaration is a duplicate, so do nothing

			// else it's an extension
		} else {
			// parse the subtype and supertype
			splitted := strings.Split(typeDec, "<")
			if len(splitted) != 2 {
				panic(fmt.Sprintf("invalid syntax in type declaration `%s`; only one extension is permitted per declaration", typeDec))
			}
			sub, super := strings.TrimSpace(splitted[0]), strings.TrimSpace(splitted[1])
			// make sure that the supertype in a declaration actually exists
			_, there := pkgr.TypeMap[super]
			if !there {
				panic(fmt.Sprintf("cannot extend type `%s` before it has been declared", super))
			}
			// check for conflicts with previous declarations
			// (and incidentally ensure that subtypes always have a higher id than their supertypes
			extendee, subHasAlreadyExtended := pkgr.SuperclassOf[sub]
			if subHasAlreadyExtended /* && extendee != super */ {
				var previousDec string
				if extendee == "" {
					previousDec = fmt.Sprintf("`%s` (extends nothing)", sub)
				} else if extendee == super {
					previousDec = fmt.Sprintf("`%s < %s` (duplicates not allowed)", sub, extendee)
				} else {
					previousDec = fmt.Sprintf("`%s < %s`", sub, extendee)
				}
				panic(fmt.Sprintf("type declaration `%s` conflicts with previous declaration %s", typeDec, previousDec))
			}
			// if we get this far, we can proceed with the type extension
			pkgr.TypeMap[sub] = len(pkgr.TypeMap)
			pkgr.SuperclassOf[sub] = super
		}
	}
}