Skip to content

Commit

Permalink
cmd/probs: fix handling of optional directory argument
Browse files Browse the repository at this point in the history
If a positional argument is passed to 'bbi probs', the command looks
there for model files.  Otherwise it falls back to using the current
working directory.

The handling of the argument is incorrect unless it happens to point
to the current working directory.  The model files come back relative
from ListModels, so modSummaries will look in the current directory
for them despite the directory being specified.

Fix the error by making the files absolute before passing them to
modSummaries.
  • Loading branch information
kyleam committed Aug 15, 2024
1 parent 1e5ab8f commit ba94b93
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ func probs(_ *cobra.Command, args []string) error {
if err != nil {
return err
}
modelSummaries := modSummaries(AppFs, modelFiles)

filesAbs := make([]string, len(modelFiles))
for i := range modelFiles {
filesAbs[i] = filepath.Join(dirPath, modelFiles[i])
}

modelSummaries := modSummaries(AppFs, filesAbs)

if Json {
err = utils.PrintJSON(modelSummaries)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions integration/nmless/bbi_probs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ func TestProbs(tt *testing.T) {
}
}
})

t.Run("directory argument", func(t *wrapt.T) {
cmd1 := exec.Command("bbi", "nonmem", "probs")
cmd1.Dir = dir

bs1, err := cmd1.Output()
if err != nil {
t.Fatal(err)
}

cmd2 := exec.Command("bbi", "nonmem", "probs", dir)
bs2, err := cmd2.Output()
if err != nil {
t.Fatal(err)
}

t.A.Equal(bs1, bs2)
})
}

func TestProbsErrors(tt *testing.T) {
Expand Down

0 comments on commit ba94b93

Please sign in to comment.