Exemplo n.º 1
0
func TestHomebrew(t *testing.T) {
	if err := homebrew.Tap("orchestra-pit/fake"); err != nil {
		t.Errorf("Tap: %v", err)
	}

	if err := homebrew.Install("orchestra-pit/fake/stub", nil); err != nil {
		t.Errorf("Install: %v", err)
	}

	if err := homebrew.IsInstalled("orchestra-pit/fake/stub", "", nil); err != nil {
		t.Errorf("IsInstalled: %v", err)
	}

	if err := homebrew.IsInstalled("orchestra-pit/fake/stub", "0.3", nil); err != nil {
		t.Errorf("IsInstalled: %v", err)
	}

	if err := homebrew.Uninstall("orchestra-pit/fake/stub"); err != nil {
		t.Errorf("Uninstall: %v", err)
	}

	if err := homebrew.IsNotInstalled("orchestra-pit/fake/stub"); err != nil {
		t.Errorf("IsNotInstalled: %v", err)
	}

	if err := homebrew.Install("orchestra-pit/fake/stub", []string{"--with-something-awesome"}); err != nil {
		t.Errorf("Install: %v", err)
	}

	if err := homebrew.IsInstalled("orchestra-pit/fake/stub", "0.3", []string{"--with-something-awesome"}); err != nil {
		t.Errorf("IsInstalled: %v", err)
	}

	if err := homebrew.Uninstall("orchestra-pit/fake/stub"); err != nil {
		t.Errorf("Uninstall: %v", err)
	}

	if err := homebrew.Untap("orchestra-pit/fake"); err != nil {
		t.Errorf("Untap: %v", err)
	}
}
func (s *Installed) apply() error {
	if s.Update {
		if err := update.do(); err != nil {
			return err
		}
	}

	// if the package name contains the slash, tap the repository.
	if i := strings.LastIndex(s.Name, "/"); i > 0 {
		if err := homebrew.Tap(s.Name[0:i]); err != nil {
			return err
		}
	}

	// try to uninstall the named package if the different version is installed.
	if err := homebrew.IsInstalled(s.Name, s.Version, s.Options); err == nil {
		err := homebrew.Uninstall(s.Name)
		if err != nil {
			return err
		}
	}

	return homebrew.Install(s.Name, s.Options)
}