Blender finder: report only the first line of stdout

This commit is contained in:
Sybren A. Stüvel 2022-07-14 18:41:50 +02:00
parent 8b494dc448
commit 86bccf3aa9
2 changed files with 14 additions and 4 deletions

View File

@ -92,6 +92,11 @@ func getBlenderVersion(ctx context.Context, commandline string) (string, error)
return "", err
}
version := strings.TrimSpace(string(stdoutStderr))
return version, nil
version := string(stdoutStderr)
lines := strings.SplitN(version, "\n", 2)
if len(lines) > 0 {
version = lines[0]
}
return strings.TrimSpace(version), nil
}

View File

@ -19,8 +19,11 @@ func TestGetBlenderVersion(t *testing.T) {
}
path, err := exec.LookPath("blender")
if err != nil {
path, err = fileAssociation()
if !assert.NoError(t, err) {
t.Fatal("running with -withBlender requires having a `blender` command on $PATH")
t.Fatal("running with -withBlender requires having a `blender` command on $PATH or a file association to .blend files")
}
}
ctx := context.Background()
@ -29,6 +32,8 @@ func TestGetBlenderVersion(t *testing.T) {
version, err := getBlenderVersion(ctx, path)
if assert.NoError(t, err) {
assert.Contains(t, version, "Blender")
assert.NotContains(t, version, "\n", "Everything after the first newline should be skipped")
assert.NotContains(t, version, "\r", "Everything after the first line feed should be skipped")
}
// Try non-existing executable: