Skip to content

Commit

Permalink
Implement '--test262-update'
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Aug 22, 2023
1 parent 6470f78 commit a3dc4e8
Showing 1 changed file with 72 additions and 26 deletions.
98 changes: 72 additions & 26 deletions boa_tester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,22 @@ enum Cli {
verbose: u8,

/// Path to the Test262 suite.
#[arg(long, value_hint = ValueHint::DirPath)]
#[arg(
long,
value_hint = ValueHint::DirPath,
conflicts_with = "test262_update",
conflicts_with = "test262_commit"
)]
test262_path: Option<PathBuf>,

/// Specify the Test262 commit when cloning the repository.
#[arg(long)]
#[arg(long, conflicts_with = "test262_update")]
test262_commit: Option<String>,

/// Update Test262 commit of the repository.
#[arg(long)]
test262_update: bool,

/// Which specific test or test suite to run. Should be a path relative to the Test262 directory: e.g. "test/language/types/number"
#[arg(short, long, default_value = "test", value_hint = ValueHint::AnyPath)]
suite: PathBuf,
Expand Down Expand Up @@ -219,6 +228,7 @@ fn main() -> Result<()> {
verbose,
test262_path,
test262_commit,
test262_update,
suite,
output,
optimize,
Expand All @@ -230,7 +240,7 @@ fn main() -> Result<()> {
let test262_path = if let Some(path) = test262_path.as_deref() {
path
} else {
clone_test262(test262_commit.as_deref(), verbose)?;
clone_test262(test262_update, test262_commit.as_deref(), verbose)?;

Path::new(DEFAULT_TEST262_DIRECTORY)
};
Expand Down Expand Up @@ -259,7 +269,8 @@ fn main() -> Result<()> {
}
}

fn get_commit_hash(branch: &str) -> Result<(String, String)> {
/// Returns the commit hash and commit message of the provided branch name.
fn get_last_branch_commit(branch: &str) -> Result<(String, String)> {
let result = Command::new("git")
.arg("log")
.args(["-n", "1"])
Expand All @@ -284,7 +295,29 @@ fn get_commit_hash(branch: &str) -> Result<(String, String)> {
Ok((hash.into(), message.into()))
}

fn clone_test262(commit: Option<&str>, verbose: u8) -> Result<()> {
fn reset_test262_commit(commit: &str, verbose: u8) -> Result<()> {
if verbose != 0 {
println!("Reset test262 to commit: {commit}...");
}

let result = Command::new("git")
.arg("reset")
.arg("--hard")
.arg(commit)
.current_dir(DEFAULT_TEST262_DIRECTORY)
.status()?;

if !result.success() {
bail!(
"test262 commit {commit} checkout failed with return code: {:?}",
result.code()
);
}

Ok(())
}

fn clone_test262(update: bool, commit: Option<&str>, verbose: u8) -> Result<()> {
const TEST262_REPOSITORY: &str = "https://github.com/tc39/test262";

if Path::new(DEFAULT_TEST262_DIRECTORY).is_dir() {
Expand All @@ -298,21 +331,43 @@ fn clone_test262(commit: Option<&str>, verbose: u8) -> Result<()> {

if !result.success() {
bail!(
"test262 fetching latest failed with return code {:?}",
"Test262 fetching latest failed with return code {:?}",
result.code()
);
}

let (current_commit_hash, current_commit_message) = get_last_branch_commit("HEAD")?;

if let Some(commit) = commit {
if current_commit_hash != commit {
println!("Test262 switching to commit {commit}...");
reset_test262_commit(commit, verbose)?;
}
return Ok(());
}

if verbose != 0 {
println!("Checking latest test262 with current HEAD...");
println!("Checking latest Test262 with current HEAD...");
}
let (current_commit_hash, current_commit_message) = get_commit_hash("HEAD")?;
let (latest_commit_hash, latest_commit_message) = get_commit_hash("origin/main")?;
let (latest_commit_hash, latest_commit_message) = get_last_branch_commit("origin/main")?;

if current_commit_hash != latest_commit_hash {
println!("Warning:");
println!(" Current commit HEAD: {current_commit_hash} {current_commit_message}");
println!(" Latest commit: {latest_commit_hash} {latest_commit_message}");
if verbose != 0 {
if update {
println!("Updating Test262 repository:");
} else {
println!("Warning Test262 repository is not in sync, use '--test262-update' to automatically update it:");
}
}

if verbose != 0 {
println!(" Current commit: {current_commit_hash} {current_commit_message}");
println!(" Latest commit: {latest_commit_hash} {latest_commit_message}");
}

if update {
reset_test262_commit(&latest_commit_hash, verbose)?;
}
}

return Ok(());
Expand All @@ -327,26 +382,17 @@ fn clone_test262(commit: Option<&str>, verbose: u8) -> Result<()> {

if !result.success() {
bail!(
"test262 cloning failed with return code {:?}",
"Cloning Test262 repository failed with return code {:?}",
result.code()
);
}

if let Some(commit) = commit {
println!("Reset test262 to commit: {commit}...");
let result = Command::new("git")
.arg("reset")
.arg("--hard")
.arg(commit)
.current_dir(DEFAULT_TEST262_DIRECTORY)
.status()?;

if !result.success() {
bail!(
"test262 commit {commit} checkout failed with return code: {:?}",
result.code()
);
if verbose != 0 {
println!("Reset Test262 to commit: {commit}...");
}

reset_test262_commit(commit, verbose)?;
}

Ok(())
Expand Down

0 comments on commit a3dc4e8

Please sign in to comment.