This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git

commit 81c84a27d1f1332c84dbc17dd7583399dfca0991
Author: Szymon Janc <[email protected]>
AuthorDate: Thu Oct 15 17:57:26 2026 +0200

    newt: Run newt upgrade tests as Go tests
    
    Move upgrade test projects and dummy repos to newt/testdata/upgrade and
    run them from Go tests. The tests import the dummy repos into a
    temporary directory and use a temporary global git config to map the
    placeholder URL to them, so the user's git config is not modified.
    
    Outputs are compared ignoring white space, as "diff -w" did.
    
    Assisted-by: Claude:claude-opus-5-5
---
 .github/workflows/test_upgrade.yml                 | 139 ---------------
 .../testdata/upgrade}/allowed-ignored/expected.txt |   0
 .../testdata/upgrade}/allowed-ignored/project.yml  |   0
 .../testdata/upgrade}/dummy-repos/README.md        |  17 +-
 .../upgrade}/dummy-repos/mynewt-dummy-repo-01.fi   |   0
 .../upgrade}/dummy-repos/mynewt-dummy-repo-02.fi   |   0
 .../upgrade}/dummy-repos/mynewt-dummy-repo-03.fi   |   0
 .../upgrade}/dummy-repos/mynewt-dummy-repo-04.fi   |   0
 .../upgrade}/dummy-repos/mynewt-dummy-repo-05.fi   |   0
 .../testdata/upgrade}/dummy-repos/setup.sh         |   0
 .../testdata/upgrade}/fail/conflict01/expected.txt |   0
 .../testdata/upgrade}/fail/conflict01/project.yml  |   0
 .../testdata/upgrade}/fail/conflict02/expected.txt |   0
 .../testdata/upgrade}/fail/conflict02/project.yml  |   0
 .../upgrade}/fail/core-ignored/expected.txt        |   0
 .../upgrade}/fail/core-ignored/project.yml         |   0
 .../upgrade}/fail/nonexistent-commit/expected.txt  |   0
 .../upgrade}/fail/nonexistent-commit/project.yml   |   0
 .../upgrade}/fail/nonexistent-version/expected.txt |   0
 .../upgrade}/fail/nonexistent-version/project.yml  |   0
 .../testdata/upgrade}/success/basic01/expected.txt |   0
 .../testdata/upgrade}/success/basic01/project.yml  |   0
 .../testdata/upgrade}/success/basic02/expected.txt |   0
 .../testdata/upgrade}/success/basic02/project.yml  |   0
 .../testdata/upgrade}/success/basic03/expected.txt |   0
 .../testdata/upgrade}/success/basic03/project.yml  |   0
 .../upgrade}/success/branches01/expected.txt       |   0
 .../upgrade}/success/branches01/project.yml        |   0
 .../upgrade}/success/dup-overrides/expected.txt    |   0
 .../upgrade}/success/dup-overrides/project.yml     |   0
 .../testdata/upgrade}/success/inferrc/expected.txt |   0
 .../testdata/upgrade}/success/inferrc/project.yml  |   0
 .../upgrade}/success/one-override/expected.txt     |   0
 .../upgrade}/success/one-override/project.yml      |   0
 .../upgrade}/success/three-overrides/expected.txt  |   0
 .../upgrade}/success/three-overrides/project.yml   |   0
 newt/upgrade_test.go                               | 190 +++++++++++++++++++++
 37 files changed, 201 insertions(+), 145 deletions(-)

diff --git a/.github/workflows/test_upgrade.yml 
b/.github/workflows/test_upgrade.yml
deleted file mode 100644
index 8ad7056a..00000000
--- a/.github/workflows/test_upgrade.yml
+++ /dev/null
@@ -1,139 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#  http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-name: Test upgrade
-
-on: [push, pull_request]
-
-jobs:
-  populate-projects:
-    runs-on: ubuntu-latest
-    outputs:
-      projects_success: ${{ steps.set-matrix.outputs.projects_success }}
-      projects_fail: ${{ steps.set-matrix.outputs.projects_fail }}
-    steps:
-      - uses: actions/checkout@v7
-      - id: set-matrix
-        shell: bash
-        run: |
-             echo "::set-output name=projects_success::$(ls 
.github/newt_upgrade/success/ | jq -R -s -c 'split("\n")[:-1]')"
-             echo "::set-output name=projects_fail::$(ls 
.github/newt_upgrade/fail/ | jq -R -s -c 'split("\n")[:-1]')"
-
-  test_upgrade_success:
-    name: newt upgrade (success)
-    needs: populate-projects
-    strategy:
-      fail-fast: false
-      matrix:
-        os: [ubuntu-latest, windows-latest, macos-latest]
-        projects: ${{ 
fromJson(needs.populate-projects.outputs.projects_success) }}
-    runs-on: ${{ matrix.os }}
-    steps:
-      - uses: actions/checkout@v7
-      - uses: actions/setup-go@v7
-        with:
-          go-version: 'stable'
-      - name: Build newt
-        working-directory: newt
-        shell: bash
-        run: |
-             go version
-             go build
-             echo  ${GITHUB_WORKSPACE}/newt >> $GITHUB_PATH
-             git config --global url."https://github.com/".insteadOf 
"[email protected]:"
-      - name: Setup dummy repos
-        shell: bash
-        run: .github/newt_upgrade/dummy-repos/setup.sh 
"$RUNNER_TEMP/dummy-repos"
-      - name: Test upgrade success
-        shell: bash
-        working-directory: .github/newt_upgrade/success/${{ matrix.projects }}
-        run: |
-             echo "Checking target ${{ matrix.targets }}"
-             echo "Test initial install"
-             newt upgrade
-             newt info | grep mynewt-dummy | diff -w expected.txt -
-             echo "Checking out repos to origin/master"
-             for repo in `ls repos`; do git -C repos/"$repo" checkout -q 
origin/master; done
-             echo "Test upgrade"
-             newt upgrade
-             newt info | grep mynewt-dummy | diff -w expected.txt -
-
-  test_upgrade_fail:
-    name: newt upgrade (fail)
-    needs: populate-projects
-    strategy:
-      fail-fast: false
-      matrix:
-        os: [ubuntu-latest, windows-latest, macos-latest]
-        projects: ${{ fromJson(needs.populate-projects.outputs.projects_fail) 
}}
-    runs-on: ${{ matrix.os }}
-    steps:
-      - uses: actions/checkout@v7
-      - uses: actions/setup-go@v7
-        with:
-          go-version: 'stable'
-      - name: Build newt
-        working-directory: newt
-        shell: bash
-        run: |
-             go version
-             go build
-             echo  ${GITHUB_WORKSPACE}/newt >> $GITHUB_PATH
-             git config --global url."https://github.com/".insteadOf 
"[email protected]:"
-      - name: Setup dummy repos
-        shell: bash
-        run: .github/newt_upgrade/dummy-repos/setup.sh 
"$RUNNER_TEMP/dummy-repos"
-      - name: Test upgrade fail
-        shell: bash
-        working-directory: .github/newt_upgrade/fail/${{ matrix.projects }}
-        run: |
-             echo "Checking target ${{ matrix.targets }}"
-             ! newt upgrade &> tmp.txt
-             cat tmp.txt | tail -n `wc -l < expected.txt` | diff -w 
expected.txt -
-
-  test_upgrade_filters:
-    name: newt upgrade (filters)
-    strategy:
-      fail-fast: false
-      matrix:
-        os: [ubuntu-latest, windows-latest, macos-latest]
-    runs-on: ${{ matrix.os }}
-    steps:
-      - uses: actions/checkout@v7
-      - uses: actions/setup-go@v7
-        with:
-          go-version: 'stable'
-      - name: Build newt
-        working-directory: newt
-        shell: bash
-        run: |
-          go version
-          go build
-          echo  ${GITHUB_WORKSPACE}/newt >> $GITHUB_PATH
-          git config --global url."https://github.com/".insteadOf 
"[email protected]:"
-      - name: Setup dummy repos
-        shell: bash
-        run: .github/newt_upgrade/dummy-repos/setup.sh 
"$RUNNER_TEMP/dummy-repos"
-      - name: Test upgrade allowed-ignored
-        shell: bash
-        working-directory: .github/newt_upgrade/allowed-ignored
-        run: |
-             echo "Test upgrade"
-             newt upgrade
-             ls -1 repos | diff -w expected.txt -
diff --git a/.github/newt_upgrade/allowed-ignored/expected.txt 
b/newt/testdata/upgrade/allowed-ignored/expected.txt
similarity index 100%
rename from .github/newt_upgrade/allowed-ignored/expected.txt
rename to newt/testdata/upgrade/allowed-ignored/expected.txt
diff --git a/.github/newt_upgrade/allowed-ignored/project.yml 
b/newt/testdata/upgrade/allowed-ignored/project.yml
similarity index 100%
rename from .github/newt_upgrade/allowed-ignored/project.yml
rename to newt/testdata/upgrade/allowed-ignored/project.yml
diff --git a/.github/newt_upgrade/dummy-repos/README.md 
b/newt/testdata/upgrade/dummy-repos/README.md
similarity index 73%
rename from .github/newt_upgrade/dummy-repos/README.md
rename to newt/testdata/upgrade/dummy-repos/README.md
index f85a4f78..45b5a7c1 100644
--- a/.github/newt_upgrade/dummy-repos/README.md
+++ b/newt/testdata/upgrade/dummy-repos/README.md
@@ -25,14 +25,19 @@ The `*.fi` files are `git fast-export` streams of the repos 
used by the
 `newt upgrade` tests. The test projects refer to them with the
 placeholder URL `https://dummy.invalid/<repo>.git`.
 
-`setup.sh <dest-dir>` imports the streams as bare repos into `<dest-dir>`
-and sets a global git `insteadOf` rule that maps the placeholder URL to
-them. To run the tests locally without touching your git config, point
-`GIT_CONFIG_GLOBAL` at a scratch file first:
+The tests in `newt/upgrade_test.go` import the streams into a temporary
+directory and map the placeholder URL to it, so they need only `git`:
+
+    go test -run TestUpgrade ./newt
+
+`setup.sh <dest-dir>` does the same for running newt by hand. It imports
+the streams as bare repos into `<dest-dir>` and sets a global git
+`insteadOf` rule that maps the placeholder URL to them. To avoid touching
+your git config, point `GIT_CONFIG_GLOBAL` at a scratch file first:
 
     export GIT_CONFIG_GLOBAL=/tmp/dummy-gitconfig
-    .github/newt_upgrade/dummy-repos/setup.sh /tmp/dummy-repos
-    cd .github/newt_upgrade/success/basic01
+    newt/testdata/upgrade/dummy-repos/setup.sh /tmp/dummy-repos
+    cd newt/testdata/upgrade/success/basic01
     newt upgrade
 
 Commit hashes are deterministic, so `expected.txt` files and `-commit`
diff --git a/.github/newt_upgrade/dummy-repos/mynewt-dummy-repo-01.fi 
b/newt/testdata/upgrade/dummy-repos/mynewt-dummy-repo-01.fi
similarity index 100%
rename from .github/newt_upgrade/dummy-repos/mynewt-dummy-repo-01.fi
rename to newt/testdata/upgrade/dummy-repos/mynewt-dummy-repo-01.fi
diff --git a/.github/newt_upgrade/dummy-repos/mynewt-dummy-repo-02.fi 
b/newt/testdata/upgrade/dummy-repos/mynewt-dummy-repo-02.fi
similarity index 100%
rename from .github/newt_upgrade/dummy-repos/mynewt-dummy-repo-02.fi
rename to newt/testdata/upgrade/dummy-repos/mynewt-dummy-repo-02.fi
diff --git a/.github/newt_upgrade/dummy-repos/mynewt-dummy-repo-03.fi 
b/newt/testdata/upgrade/dummy-repos/mynewt-dummy-repo-03.fi
similarity index 100%
rename from .github/newt_upgrade/dummy-repos/mynewt-dummy-repo-03.fi
rename to newt/testdata/upgrade/dummy-repos/mynewt-dummy-repo-03.fi
diff --git a/.github/newt_upgrade/dummy-repos/mynewt-dummy-repo-04.fi 
b/newt/testdata/upgrade/dummy-repos/mynewt-dummy-repo-04.fi
similarity index 100%
rename from .github/newt_upgrade/dummy-repos/mynewt-dummy-repo-04.fi
rename to newt/testdata/upgrade/dummy-repos/mynewt-dummy-repo-04.fi
diff --git a/.github/newt_upgrade/dummy-repos/mynewt-dummy-repo-05.fi 
b/newt/testdata/upgrade/dummy-repos/mynewt-dummy-repo-05.fi
similarity index 100%
rename from .github/newt_upgrade/dummy-repos/mynewt-dummy-repo-05.fi
rename to newt/testdata/upgrade/dummy-repos/mynewt-dummy-repo-05.fi
diff --git a/.github/newt_upgrade/dummy-repos/setup.sh 
b/newt/testdata/upgrade/dummy-repos/setup.sh
similarity index 100%
rename from .github/newt_upgrade/dummy-repos/setup.sh
rename to newt/testdata/upgrade/dummy-repos/setup.sh
diff --git a/.github/newt_upgrade/fail/conflict01/expected.txt 
b/newt/testdata/upgrade/fail/conflict01/expected.txt
similarity index 100%
rename from .github/newt_upgrade/fail/conflict01/expected.txt
rename to newt/testdata/upgrade/fail/conflict01/expected.txt
diff --git a/.github/newt_upgrade/fail/conflict01/project.yml 
b/newt/testdata/upgrade/fail/conflict01/project.yml
similarity index 100%
rename from .github/newt_upgrade/fail/conflict01/project.yml
rename to newt/testdata/upgrade/fail/conflict01/project.yml
diff --git a/.github/newt_upgrade/fail/conflict02/expected.txt 
b/newt/testdata/upgrade/fail/conflict02/expected.txt
similarity index 100%
rename from .github/newt_upgrade/fail/conflict02/expected.txt
rename to newt/testdata/upgrade/fail/conflict02/expected.txt
diff --git a/.github/newt_upgrade/fail/conflict02/project.yml 
b/newt/testdata/upgrade/fail/conflict02/project.yml
similarity index 100%
rename from .github/newt_upgrade/fail/conflict02/project.yml
rename to newt/testdata/upgrade/fail/conflict02/project.yml
diff --git a/.github/newt_upgrade/fail/core-ignored/expected.txt 
b/newt/testdata/upgrade/fail/core-ignored/expected.txt
similarity index 100%
rename from .github/newt_upgrade/fail/core-ignored/expected.txt
rename to newt/testdata/upgrade/fail/core-ignored/expected.txt
diff --git a/.github/newt_upgrade/fail/core-ignored/project.yml 
b/newt/testdata/upgrade/fail/core-ignored/project.yml
similarity index 100%
rename from .github/newt_upgrade/fail/core-ignored/project.yml
rename to newt/testdata/upgrade/fail/core-ignored/project.yml
diff --git a/.github/newt_upgrade/fail/nonexistent-commit/expected.txt 
b/newt/testdata/upgrade/fail/nonexistent-commit/expected.txt
similarity index 100%
rename from .github/newt_upgrade/fail/nonexistent-commit/expected.txt
rename to newt/testdata/upgrade/fail/nonexistent-commit/expected.txt
diff --git a/.github/newt_upgrade/fail/nonexistent-commit/project.yml 
b/newt/testdata/upgrade/fail/nonexistent-commit/project.yml
similarity index 100%
rename from .github/newt_upgrade/fail/nonexistent-commit/project.yml
rename to newt/testdata/upgrade/fail/nonexistent-commit/project.yml
diff --git a/.github/newt_upgrade/fail/nonexistent-version/expected.txt 
b/newt/testdata/upgrade/fail/nonexistent-version/expected.txt
similarity index 100%
rename from .github/newt_upgrade/fail/nonexistent-version/expected.txt
rename to newt/testdata/upgrade/fail/nonexistent-version/expected.txt
diff --git a/.github/newt_upgrade/fail/nonexistent-version/project.yml 
b/newt/testdata/upgrade/fail/nonexistent-version/project.yml
similarity index 100%
rename from .github/newt_upgrade/fail/nonexistent-version/project.yml
rename to newt/testdata/upgrade/fail/nonexistent-version/project.yml
diff --git a/.github/newt_upgrade/success/basic01/expected.txt 
b/newt/testdata/upgrade/success/basic01/expected.txt
similarity index 100%
rename from .github/newt_upgrade/success/basic01/expected.txt
rename to newt/testdata/upgrade/success/basic01/expected.txt
diff --git a/.github/newt_upgrade/success/basic01/project.yml 
b/newt/testdata/upgrade/success/basic01/project.yml
similarity index 100%
rename from .github/newt_upgrade/success/basic01/project.yml
rename to newt/testdata/upgrade/success/basic01/project.yml
diff --git a/.github/newt_upgrade/success/basic02/expected.txt 
b/newt/testdata/upgrade/success/basic02/expected.txt
similarity index 100%
rename from .github/newt_upgrade/success/basic02/expected.txt
rename to newt/testdata/upgrade/success/basic02/expected.txt
diff --git a/.github/newt_upgrade/success/basic02/project.yml 
b/newt/testdata/upgrade/success/basic02/project.yml
similarity index 100%
rename from .github/newt_upgrade/success/basic02/project.yml
rename to newt/testdata/upgrade/success/basic02/project.yml
diff --git a/.github/newt_upgrade/success/basic03/expected.txt 
b/newt/testdata/upgrade/success/basic03/expected.txt
similarity index 100%
rename from .github/newt_upgrade/success/basic03/expected.txt
rename to newt/testdata/upgrade/success/basic03/expected.txt
diff --git a/.github/newt_upgrade/success/basic03/project.yml 
b/newt/testdata/upgrade/success/basic03/project.yml
similarity index 100%
rename from .github/newt_upgrade/success/basic03/project.yml
rename to newt/testdata/upgrade/success/basic03/project.yml
diff --git a/.github/newt_upgrade/success/branches01/expected.txt 
b/newt/testdata/upgrade/success/branches01/expected.txt
similarity index 100%
rename from .github/newt_upgrade/success/branches01/expected.txt
rename to newt/testdata/upgrade/success/branches01/expected.txt
diff --git a/.github/newt_upgrade/success/branches01/project.yml 
b/newt/testdata/upgrade/success/branches01/project.yml
similarity index 100%
rename from .github/newt_upgrade/success/branches01/project.yml
rename to newt/testdata/upgrade/success/branches01/project.yml
diff --git a/.github/newt_upgrade/success/dup-overrides/expected.txt 
b/newt/testdata/upgrade/success/dup-overrides/expected.txt
similarity index 100%
rename from .github/newt_upgrade/success/dup-overrides/expected.txt
rename to newt/testdata/upgrade/success/dup-overrides/expected.txt
diff --git a/.github/newt_upgrade/success/dup-overrides/project.yml 
b/newt/testdata/upgrade/success/dup-overrides/project.yml
similarity index 100%
rename from .github/newt_upgrade/success/dup-overrides/project.yml
rename to newt/testdata/upgrade/success/dup-overrides/project.yml
diff --git a/.github/newt_upgrade/success/inferrc/expected.txt 
b/newt/testdata/upgrade/success/inferrc/expected.txt
similarity index 100%
rename from .github/newt_upgrade/success/inferrc/expected.txt
rename to newt/testdata/upgrade/success/inferrc/expected.txt
diff --git a/.github/newt_upgrade/success/inferrc/project.yml 
b/newt/testdata/upgrade/success/inferrc/project.yml
similarity index 100%
rename from .github/newt_upgrade/success/inferrc/project.yml
rename to newt/testdata/upgrade/success/inferrc/project.yml
diff --git a/.github/newt_upgrade/success/one-override/expected.txt 
b/newt/testdata/upgrade/success/one-override/expected.txt
similarity index 100%
rename from .github/newt_upgrade/success/one-override/expected.txt
rename to newt/testdata/upgrade/success/one-override/expected.txt
diff --git a/.github/newt_upgrade/success/one-override/project.yml 
b/newt/testdata/upgrade/success/one-override/project.yml
similarity index 100%
rename from .github/newt_upgrade/success/one-override/project.yml
rename to newt/testdata/upgrade/success/one-override/project.yml
diff --git a/.github/newt_upgrade/success/three-overrides/expected.txt 
b/newt/testdata/upgrade/success/three-overrides/expected.txt
similarity index 100%
rename from .github/newt_upgrade/success/three-overrides/expected.txt
rename to newt/testdata/upgrade/success/three-overrides/expected.txt
diff --git a/.github/newt_upgrade/success/three-overrides/project.yml 
b/newt/testdata/upgrade/success/three-overrides/project.yml
similarity index 100%
rename from .github/newt_upgrade/success/three-overrides/project.yml
rename to newt/testdata/upgrade/success/three-overrides/project.yml
diff --git a/newt/upgrade_test.go b/newt/upgrade_test.go
new file mode 100644
index 00000000..662dce1c
--- /dev/null
+++ b/newt/upgrade_test.go
@@ -0,0 +1,190 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package main
+
+import (
+       "fmt"
+       "os"
+       "os/exec"
+       "path/filepath"
+       "strings"
+       "testing"
+)
+
+// URL used by test projects and dummy repos to refer to dummy repos.
+const dummyRepoURL = "https://dummy.invalid/";
+
+var upgradeDir = filepath.Join("testdata", "upgrade")
+
+func runGit(t *testing.T, env []string, stdin *os.File, args ...string) {
+       t.Helper()
+
+       cmd := exec.Command("git", args...)
+       cmd.Env = append(os.Environ(), env...)
+       cmd.Stdin = stdin
+
+       if out, err := cmd.CombinedOutput(); err != nil {
+               t.Fatalf("git %s failed: %s\n%s", strings.Join(args, " "), err, 
out)
+       }
+}
+
+// dummyReposEnv imports dummy repos into a temporary directory and returns
+// environment for git that makes the dummy repo URL refer to them. Global
+// and system git configuration is not used.
+func dummyReposEnv(t *testing.T) []string {
+       t.Helper()
+
+       if _, err := exec.LookPath("git"); err != nil {
+               t.Skip("git not found")
+       }
+
+       dir := t.TempDir()
+       gitConfig := filepath.Join(dir, "gitconfig")
+       env := []string{"GIT_CONFIG_GLOBAL=" + gitConfig, 
"GIT_CONFIG_NOSYSTEM=1"}
+
+       reposURL := filepath.ToSlash(dir)
+       if !strings.HasPrefix(reposURL, "/") {
+               reposURL = "/" + reposURL
+       }
+       cfg := fmt.Sprintf("[url \"file://%s/\"]\n\tinsteadOf = %s\n", reposURL,
+               dummyRepoURL)
+       if err := os.WriteFile(gitConfig, []byte(cfg), 0644); err != nil {
+               t.Fatal(err)
+       }
+
+       streams, err := filepath.Glob(filepath.Join(upgradeDir, "dummy-repos",
+               "*.fi"))
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       for _, stream := range streams {
+               repo := filepath.Join(dir,
+                       strings.TrimSuffix(filepath.Base(stream), ".fi")+".git")
+
+               f, err := os.Open(stream)
+               if err != nil {
+                       t.Fatal(err)
+               }
+
+               runGit(t, env, nil, "init", "-q", "--bare", repo)
+               runGit(t, env, f, "-C", repo, "fast-import", "--quiet")
+               runGit(t, env, nil, "-C", repo, "symbolic-ref", "HEAD",
+                       "refs/heads/master")
+               f.Close()
+       }
+
+       return env
+}
+
+// installedRepos returns names of repos installed in project.
+func installedRepos(t *testing.T, projDir string) []string {
+       t.Helper()
+
+       names := []string{}
+       for _, name := range subdirs(t, filepath.Join(projDir, "repos")) {
+               if !strings.HasPrefix(name, ".") {
+                       names = append(names, name)
+               }
+       }
+
+       return names
+}
+
+// checkDummyRepoVersions compares versions of dummy repos reported by
+// "newt info" with expected.txt in the project.
+func checkDummyRepoVersions(t *testing.T, projDir string, env []string) {
+       t.Helper()
+
+       lines := []string{}
+       out := newtOutput(t, projDir, env, "info")
+       for _, line := range strings.Split(out, "\n") {
+               if strings.Contains(line, "mynewt-dummy") {
+                       lines = append(lines, line)
+               }
+       }
+
+       checkOutput(t, "repo versions",
+               readFile(t, filepath.Join(projDir, "expected.txt")),
+               strings.Join(lines, "\n"))
+}
+
+// Each project in testdata/upgrade/success must install repos with versions
+// listed in its expected.txt, both on initial install and on upgrade from the
+// latest commit.
+func TestUpgradeSuccess(t *testing.T) {
+       env := dummyReposEnv(t)
+       successDir := filepath.Join(upgradeDir, "success")
+
+       for _, name := range subdirs(t, successDir) {
+               t.Run(name, func(t *testing.T) {
+                       t.Parallel()
+
+                       projDir := copyToTemp(t, filepath.Join(successDir, 
name))
+
+                       newtOutput(t, projDir, env, "upgrade")
+                       checkDummyRepoVersions(t, projDir, env)
+
+                       for _, repo := range installedRepos(t, projDir) {
+                               runGit(t, env, nil, "-C",
+                                       filepath.Join(projDir, "repos", repo),
+                                       "checkout", "-q", "origin/master")
+                       }
+
+                       newtOutput(t, projDir, env, "upgrade")
+                       checkDummyRepoVersions(t, projDir, env)
+               })
+       }
+}
+
+// Each project in testdata/upgrade/fail must fail to upgrade with error
+// message ending with its expected.txt.
+func TestUpgradeFail(t *testing.T) {
+       env := dummyReposEnv(t)
+       failDir := filepath.Join(upgradeDir, "fail")
+
+       for _, name := range subdirs(t, failDir) {
+               t.Run(name, func(t *testing.T) {
+                       t.Parallel()
+
+                       projDir := copyToTemp(t, filepath.Join(failDir, name))
+
+                       out, err := newtCombinedOutput(projDir, env, "upgrade")
+                       if err == nil {
+                               t.Fatalf("newt upgrade succeeded\n%s", out)
+                       }
+
+                       checkOutputTail(t, "error",
+                               readFile(t, filepath.Join(projDir, 
"expected.txt")), out)
+               })
+       }
+}
+
+// Only allowed and not ignored repos must be installed.
+func TestUpgradeAllowedIgnored(t *testing.T) {
+       env := dummyReposEnv(t)
+       projDir := copyToTemp(t, filepath.Join(upgradeDir, "allowed-ignored"))
+
+       newtOutput(t, projDir, env, "upgrade")
+
+       checkOutput(t, "installed repos",
+               readFile(t, filepath.Join(projDir, "expected.txt")),
+               strings.Join(installedRepos(t, projDir), "\n"))
+}

Reply via email to