jiri: Remove jiritest.NewX_DeprecatedEnv
In most of the tests, I replaced NewX_DeprecatedEnv with
NewFakeJiriRoot. That broke tests that used profiles, since the
fake JIRI_ROOT doesn't contain the third_party project, which is
for various profiles-related setup. The fix for those cases is
to pass -skip-profiles; that also makes the tests a bit more
hermetic, and run faster.
MultiPart: 1/2
Change-Id: Ia9de91a19b586abd59d4e65c036fb8fa8e826072
diff --git a/jiri/x_test.go b/jiri/x_test.go
index 340a4ba..ee0e643 100644
--- a/jiri/x_test.go
+++ b/jiri/x_test.go
@@ -41,11 +41,11 @@
// Set the JIRI_ROOT to the symlink created above and check that FindRoot()
// evaluates the symlink.
- oldRoot := os.Getenv("JIRI_ROOT")
- if err := os.Setenv("JIRI_ROOT", symRoot); err != nil {
+ oldRoot := os.Getenv(RootEnv)
+ if err := os.Setenv(RootEnv, symRoot); err != nil {
t.Fatalf("%v", err)
}
- defer os.Setenv("JIRI_ROOT", oldRoot)
+ defer os.Setenv(RootEnv, oldRoot)
if got, want := FindRoot(), root; got != want {
t.Fatalf("unexpected output: got %v, want %v", got, want)
}
diff --git a/jiritest/.api b/jiritest/.api
new file mode 100644
index 0000000..ebd8c36
--- /dev/null
+++ b/jiritest/.api
@@ -0,0 +1,16 @@
+pkg jiritest, func NewFakeJiriRoot(*testing.T) (*FakeJiriRoot, func())
+pkg jiritest, func NewX(*testing.T) (*jiri.X, func())
+pkg jiritest, method (FakeJiriRoot) AddHost(project.Host) error
+pkg jiritest, method (FakeJiriRoot) AddProject(project.Project) error
+pkg jiritest, method (FakeJiriRoot) AddTool(project.Tool) error
+pkg jiritest, method (FakeJiriRoot) CreateRemoteProject(string) error
+pkg jiritest, method (FakeJiriRoot) DisableRemoteManifestPush() error
+pkg jiritest, method (FakeJiriRoot) EnableRemoteManifestPush() error
+pkg jiritest, method (FakeJiriRoot) ReadLocalManifest() (*project.Manifest, error)
+pkg jiritest, method (FakeJiriRoot) ReadRemoteManifest() (*project.Manifest, error)
+pkg jiritest, method (FakeJiriRoot) UpdateUniverse(bool) error
+pkg jiritest, method (FakeJiriRoot) WriteLocalManifest(*project.Manifest) error
+pkg jiritest, method (FakeJiriRoot) WriteRemoteManifest(*project.Manifest) error
+pkg jiritest, type FakeJiriRoot struct
+pkg jiritest, type FakeJiriRoot struct, Projects map[string]string
+pkg jiritest, type FakeJiriRoot struct, X *jiri.X
diff --git a/jiritest/fake.go b/jiritest/fake.go
index cfb0d8f..6b66ed7 100644
--- a/jiritest/fake.go
+++ b/jiritest/fake.go
@@ -235,11 +235,11 @@
// UpdateUniverse synchronizes the content of the Vanadium fake based
// on the content of the remote manifest.
func (fake FakeJiriRoot) UpdateUniverse(gc bool) error {
- oldRoot := os.Getenv("JIRI_ROOT")
- if err := os.Setenv("JIRI_ROOT", fake.X.Root); err != nil {
+ oldRoot := os.Getenv(jiri.RootEnv)
+ if err := os.Setenv(jiri.RootEnv, fake.X.Root); err != nil {
return fmt.Errorf("Setenv() failed: %v", err)
}
- defer os.Setenv("JIRI_ROOT", oldRoot)
+ defer os.Setenv(jiri.RootEnv, oldRoot)
if err := project.UpdateUniverse(fake.X, gc); err != nil {
return err
}
diff --git a/jiritest/x.go b/jiritest/x.go
index 279b7c2..8772256 100644
--- a/jiritest/x.go
+++ b/jiritest/x.go
@@ -34,20 +34,3 @@
}
return &jiri.X{Context: ctx, Root: root}, cleanup
}
-
-// NewX_DeprecatedEnv relies on the deprecated JIRI_ROOT environment variable to
-// set up a new jiri.X. Tests relying on this function need to be updated to
-// not rely on the environment variable.
-func NewX_DeprecatedEnv(t *testing.T, opts *tool.ContextOpts) *jiri.X {
- root := os.Getenv(jiri.RootEnv)
- if root == "" {
- t.Fatalf("%v isn't set", jiri.RootEnv)
- }
- var ctx *tool.Context
- if opts != nil {
- ctx = tool.NewContext(*opts)
- } else {
- ctx = tool.NewDefaultContext()
- }
- return &jiri.X{Context: ctx, Root: root}
-}
diff --git a/runutil/.api b/runutil/.api
index ba929ec..a818038 100644
--- a/runutil/.api
+++ b/runutil/.api
@@ -35,17 +35,22 @@
pkg runutil, method (*Sequence) Capture(io.Writer, io.Writer) *Sequence
pkg runutil, method (*Sequence) Chdir(string) *Sequence
pkg runutil, method (*Sequence) Chmod(string, os.FileMode) *Sequence
+pkg runutil, method (*Sequence) Copy(*os.File, io.Reader) (int64, error)
+pkg runutil, method (*Sequence) Create(string) (*os.File, error)
pkg runutil, method (*Sequence) DirectoryExists(string) (bool, error)
pkg runutil, method (*Sequence) Done() error
+pkg runutil, method (*Sequence) Env(map[string]string) *Sequence
pkg runutil, method (*Sequence) Error() error
pkg runutil, method (*Sequence) FileExists(string) (bool, error)
-pkg runutil, method (*Sequence) GetOpts() Opts
pkg runutil, method (*Sequence) IsDir(string) (bool, error)
pkg runutil, method (*Sequence) Last(string, ...string) error
pkg runutil, method (*Sequence) MkdirAll(string, os.FileMode) *Sequence
pkg runutil, method (*Sequence) Open(string) (*os.File, error)
-pkg runutil, method (*Sequence) Opts(Opts) *Sequence
+pkg runutil, method (*Sequence) OpenFile(string, int, os.FileMode) (*os.File, error)
pkg runutil, method (*Sequence) Output([]string) *Sequence
+pkg runutil, method (*Sequence) Popd() *Sequence
+pkg runutil, method (*Sequence) Pushd(string) *Sequence
+pkg runutil, method (*Sequence) Read(io.Reader) *Sequence
pkg runutil, method (*Sequence) ReadDir(string) ([]os.FileInfo, error)
pkg runutil, method (*Sequence) ReadFile(string) ([]byte, error)
pkg runutil, method (*Sequence) Remove(string) *Sequence
@@ -56,6 +61,7 @@
pkg runutil, method (*Sequence) Symlink(string, string) *Sequence
pkg runutil, method (*Sequence) TempDir(string, string) (string, error)
pkg runutil, method (*Sequence) Timeout(time.Duration) *Sequence
+pkg runutil, method (*Sequence) WriteFile(string, []byte, os.FileMode) *Sequence
pkg runutil, method (*Start) Command(string, ...string) (*exec.Cmd, error)
pkg runutil, method (*Start) CommandWithOpts(Opts, string, ...string) (*exec.Cmd, error)
pkg runutil, method (Run) Opts() Opts
diff --git a/runutil/sequence.go b/runutil/sequence.go
index f01d1ea..44f2c68 100644
--- a/runutil/sequence.go
+++ b/runutil/sequence.go
@@ -263,12 +263,13 @@
if len(args) == 0 {
return ""
}
- out := &bytes.Buffer{}
+ var out bytes.Buffer
for _, a := range args {
- if _, ok := a.(string); ok {
- out.WriteString(fmt.Sprintf(" ,%q", a))
- } else {
- out.WriteString(fmt.Sprintf(" ,%s", a))
+ switch at := a.(type) {
+ case string:
+ fmt.Fprintf(&out, ", %q", at)
+ default:
+ fmt.Fprintf(&out, ", %v", a)
}
}
return out.String()
@@ -278,11 +279,9 @@
if len(args) == 0 {
return ""
}
- out := &bytes.Buffer{}
+ var out bytes.Buffer
for _, a := range args {
- out.WriteString(", \"")
- out.WriteString(a)
- out.WriteString("\"")
+ fmt.Fprintf(&out, ", %q", a)
}
return out.String()
}
@@ -347,7 +346,7 @@
return s
}
defer s.initAndDefer()()
- s.setError(s.r.FunctionWithOpts(s.getOpts(), fn, format, args...), fmt.Sprintf("Call(%s,%s%s)", fn, format, fmtArgs(args)))
+ s.setError(s.r.FunctionWithOpts(s.getOpts(), fn, format, args...), fmt.Sprintf("Call(%s%s)", format, fmtArgs(args)))
return s
}