Esempio n. 1
0
File: set.go Progetto: vito/gocart
func (s *Set) UnmarshalText(text []byte) error {
	lines := bufio.NewScanner(bytes.NewReader(text))

	for lines.Scan() {
		words := bufio.NewScanner(bytes.NewReader(lines.Bytes()))
		words.Split(bufio.ScanWords)

		count := 0
		dep := dependency.Dependency{}

		for words.Scan() {
			if strings.HasPrefix(words.Text(), "#") {
				break
			}

			if count == 0 {
				dep.Path = words.Text()
			} else if count == 1 {
				if words.Text() == "*" {
					dep.BleedingEdge = true
				} else {
					dep.Version = words.Text()
				}
			} else if count == 2 {
				dep.Tags = strings.Split(words.Text(), ",")
			}

			count++
		}

		if count == 0 {
			// blank line
			continue
		}

		if count == 1 {
			return MissingVersionError{dep.Path}
		}

		// check for dupes
		for _, existing := range s.Dependencies {
			if strings.HasPrefix(dep.Path+"/", existing.Path+"/") {
				return DuplicateDependencyError{existing, dep}
			}

			if strings.HasPrefix(existing.Path+"/", dep.Path+"/") {
				return DuplicateDependencyError{existing, dep}
			}
		}

		s.Dependencies = append(s.Dependencies, dep)
	}

	return nil
}
Esempio n. 2
0
					},
				))
			})
		})

		Context("when the dependency is bleeding-edge", func() {
			Context("and the repository exists", func() {
				BeforeEach(func() {
					gopath, _ := gopath.InstallationDirectory(os.Getenv("GOPATH"))

					err := os.MkdirAll(dependency.FullPath(gopath), 0755)
					Ω(err).ShouldNot(HaveOccurred())
				})

				It("fast-forwards it, but otherwise leaves it alone", func() {
					dependency.BleedingEdge = true

					runner.WhenRunning(fake_command_runner.CommandSpec{
						Path: exec.Command("git").Path,
						Args: []string{"rev-parse", "HEAD"},
					}, func(cmd *exec.Cmd) error {
						cmd.Stdout.Write([]byte("some-sha\n"))
						return nil
					})

					dep, err := fetcher.Fetch(dependency)
					Expect(err).ToNot(HaveOccurred())

					Ω(runner).Should(HaveExecutedSerially(
						fake_command_runner.CommandSpec{
							Path: exec.Command("go").Path,