Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
//! the tools.

use anyhow::{Ok, Result, anyhow};
use clap::{Parser, ValueEnum};
use std::path::Path;
use clap::{Parser, Subcommand};
use std::path::{Path, PathBuf};
use std::{env, process::Command};

fn main() -> Result<()> {
Expand All @@ -38,16 +38,20 @@ fn main() -> Result<()> {
)]
struct Cli {
/// The task to execute
#[arg(value_enum)]
#[command(subcommand)]
task: Task,
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
#[derive(Subcommand)]
enum Task {
/// Installs the tools the project depends on.
InstallTools,
/// Runs the web driver tests in the tests directory.
WebTests,
WebTests {
/// Optional 'book html' directory - if set, will also refresh the list of slides used by slide size test.
#[arg(short, long)]
dir: Option<PathBuf>,
},
/// Tests all included Rust snippets.
RustTests,
/// Starts a web server with the course.
Expand All @@ -60,7 +64,7 @@ fn execute_task() -> Result<()> {
let cli = Cli::parse();
match cli.task {
Task::InstallTools => install_tools()?,
Task::WebTests => run_web_tests()?,
Task::WebTests { dir } => run_web_tests(dir)?,
Task::RustTests => run_rust_tests()?,
Task::Serve => start_web_server()?,
Task::Build => build()?,
Expand All @@ -79,7 +83,7 @@ fn install_tools() -> Result<()> {
let install_args = vec![
// The --locked flag is important for reproducible builds. It also
// avoids breakage due to skews between mdbook and mdbook-svgbob.
vec!["mdbook", "--locked", "--version", "0.4.48"],
vec!["mdbook", "--locked", "--version", "0.4.51"],
vec!["mdbook-svgbob", "--locked", "--version", "0.2.2"],
vec!["mdbook-pandoc", "--locked", "--version", "0.10.4"],
vec!["mdbook-i18n-helpers", "--locked", "--version", "0.3.6"],
Expand Down Expand Up @@ -112,16 +116,41 @@ fn install_tools() -> Result<()> {
Ok(())
}

fn run_web_tests() -> Result<()> {
fn run_web_tests(dir: Option<PathBuf>) -> Result<()> {
println!("Running web tests...");

let absolute_dir = dir.map(|d| d.canonicalize()).transpose()?;

if let Some(d) = &absolute_dir {
println!("Refreshing slide lists...");
let path_to_refresh_slides_script = Path::new("tests")
.join("src")
.join("slides")
.join("create-slide.list.sh");
let status = Command::new(path_to_refresh_slides_script)
.current_dir(Path::new(env!("CARGO_WORKSPACE_DIR")))
.arg(d)
.status()
.expect("Failed to execute create-slide.list.sh");

if !status.success() {
let error_message = format!(
"Command 'cargo xtask web-tests' exited with status code: {}",
status.code().unwrap()
);
return Err(anyhow!(error_message));
}
}

let path_to_tests_dir = Path::new(env!("CARGO_WORKSPACE_DIR")).join("tests");
let mut command = Command::new("npm");
command.current_dir(path_to_tests_dir.to_str().unwrap());
command.arg("test");

let status = Command::new("npm")
.current_dir(path_to_tests_dir.to_str().unwrap())
.arg("test")
.status()
.expect("Failed to execute npm test");
if let Some(d) = absolute_dir {
command.env("TEST_BOOK_DIR", d);
}
let status = command.status().expect("Failed to execute npm test");

if !status.success() {
let error_message = format!(
Expand Down
Loading