Skip to content

Commit 863909b

Browse files
authored
Fix printing of the profile in version string (xiph#2336)
Needed to use the compile time value of the PROFILE var. Trying to use the runtime value would cause the binary to fail to run when not run through cargo. Updates the binary tests to remove environment variables set via cargo, so this sort of issue will be caught in the future.
1 parent 1e7581a commit 863909b

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/bin/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use rav1e::version;
1717
use scan_fmt::scan_fmt;
1818

1919
use std::fs::File;
20+
use std::io;
2021
use std::io::prelude::*;
21-
use std::{env, io};
2222

2323
pub struct EncoderIO {
2424
pub input: Box<dyn Read>,
@@ -79,7 +79,7 @@ fn build_speed_long_help() -> String {
7979
/// Only call this once at the start of the app,
8080
/// otherwise bad things will happen.
8181
pub fn parse_cli() -> Result<CliOptions, CliError> {
82-
let profile = env::var("PROFILE").unwrap();
82+
let profile = env!("PROFILE");
8383
let ver_short = format!("{} ({})", version::short(), profile);
8484
let ver_long = format!("{} ({})", version::full(), profile);
8585
let speed_long_help = build_speed_long_help();

tests/binary.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,22 @@ mod binary {
2727
path
2828
}
2929

30+
#[cfg(not(windows))]
31+
fn get_rav1e_command() -> Command {
32+
let mut cmd = Command::cargo_bin("rav1e").unwrap();
33+
cmd.env_clear();
34+
cmd
35+
}
36+
37+
#[cfg(windows)]
38+
// `env_clear` doesn't work on Windows: https://github.com/rust-lang/rust/issues/31259
39+
fn get_rav1e_command() -> Command {
40+
Command::cargo_bin("rav1e").unwrap()
41+
}
42+
3043
#[test]
3144
fn one_pass_qp_based() {
32-
let mut cmd = Command::cargo_bin("rav1e").unwrap();
45+
let mut cmd = get_rav1e_command();
3346
let outfile = get_tempfile_path("ivf");
3447

3548
cmd
@@ -45,7 +58,7 @@ mod binary {
4558

4659
#[test]
4760
fn one_pass_bitrate_based() {
48-
let mut cmd = Command::cargo_bin("rav1e").unwrap();
61+
let mut cmd = get_rav1e_command();
4962
let outfile = get_tempfile_path("ivf");
5063

5164
cmd
@@ -64,7 +77,7 @@ mod binary {
6477
let outfile = get_tempfile_path("ivf");
6578
let passfile = get_tempfile_path("pass");
6679

67-
let mut cmd1 = Command::cargo_bin("rav1e").unwrap();
80+
let mut cmd1 = get_rav1e_command();
6881
cmd1
6982
.arg("--bitrate")
7083
.arg("1000")
@@ -77,7 +90,7 @@ mod binary {
7790
.assert()
7891
.success();
7992

80-
let mut cmd2 = Command::cargo_bin("rav1e").unwrap();
93+
let mut cmd2 = get_rav1e_command();
8194
cmd2
8295
.arg("--bitrate")
8396
.arg("1000")
@@ -95,7 +108,7 @@ mod binary {
95108
let outfile = get_tempfile_path("ivf");
96109
let passfile = get_tempfile_path("pass");
97110

98-
let mut cmd1 = Command::cargo_bin("rav1e").unwrap();
111+
let mut cmd1 = get_rav1e_command();
99112
cmd1
100113
.arg("--reservoir-frame-delay")
101114
.arg("14")
@@ -110,7 +123,7 @@ mod binary {
110123
.assert()
111124
.success();
112125

113-
let mut cmd2 = Command::cargo_bin("rav1e").unwrap();
126+
let mut cmd2 = get_rav1e_command();
114127
cmd2
115128
.arg("--reservoir-frame-delay")
116129
.arg("14")

0 commit comments

Comments
 (0)