Skip to content

Commit

Permalink
Initial version of UI tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexhuszagh committed Nov 5, 2022
1 parent 35a1e17 commit 8c32d27
Show file tree
Hide file tree
Showing 7 changed files with 549 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions ci/test-ui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# shellcheck disable=SC1091

set -eo pipefail

ci_dir=$(dirname "${BASH_SOURCE[0]}")
ci_dir=$(realpath "${ci_dir}")
. "${ci_dir}"/shared.sh

if [[ -z "${TARGET}" ]]; then
export TARGET="x86_64-unknown-linux-gnu"
fi

cargo xtask ui-test \
--target "${TARGET}" \
--engine "${CROSS_ENGINE}" \
--verbose
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn fmt_subcommands(stdout: &str, msg_info: &mut MessageInfo) -> Result<()> {
}
if !host.is_empty() {
msg_info.print("Host Commands:")?;
for line in &cross {
for line in &host {
msg_info.print(line)?;
}
}
Expand Down
1 change: 1 addition & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ once_cell = "1.15"
semver = "1"
chrono = "0.4"
wildmatch = "2.1.1"
tempfile = "3.3.0"
14 changes: 14 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub mod crosstool;
pub mod hooks;
pub mod install_git_hooks;
pub mod target_info;
pub mod temp;
pub mod ui;
pub mod util;

use ci::CiJob;
Expand All @@ -23,6 +25,8 @@ use self::crosstool::ConfigureCrosstool;
use self::hooks::{Check, Test};
use self::install_git_hooks::InstallGitHooks;
use self::target_info::TargetInfo;
use self::temp::MakeTempDir;
use self::ui::UiTest;

#[derive(Parser, Debug)]
#[clap(version, about, long_about = None)]
Expand Down Expand Up @@ -65,6 +69,10 @@ enum Commands {
ValidateChangelog(ValidateChangelog),
/// Code generation
Codegen(Codegen),
/// Create temporary directory
MakeTempDir(MakeTempDir),
/// Run user-interface suite.
UiTest(UiTest),
}

fn is_toolchain(toolchain: &str) -> cross::Result<String> {
Expand Down Expand Up @@ -131,6 +139,12 @@ pub fn main() -> cross::Result<()> {
changelog::validate_changelog(args, &mut msg_info)?;
}
Commands::Codegen(args) => codegen::codegen(args)?,
Commands::MakeTempDir(args) => temp::make_temp_dir(args)?,
Commands::UiTest(args) => {
let mut msg_info = get_msg_info!(args, args.verbose)?;
let engine = get_engine!(args, msg_info)?;
ui::ui_test(args, &engine, &mut msg_info)?
}
}

Ok(())
Expand Down
35 changes: 35 additions & 0 deletions xtask/src/temp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::path::{Path, PathBuf};
use std::{fs, mem};

use crate::util;
use clap::Args;
use cross::shell::MessageInfo;
use cross::ToUtf8;

/// Create and print a temporary directory to stdout.
#[derive(Args, Debug)]
pub struct MakeTempDir {
/// `tmp` to create the temporary directory inside.
/// Defaults to `"${target_dir}/tmp"`.
tmpdir: Option<PathBuf>,
}

pub fn make_temp_dir(MakeTempDir { tmpdir }: MakeTempDir) -> cross::Result<()> {
let mut msg_info = MessageInfo::create(0, false, None)?;
let dir = temp_dir(tmpdir.as_deref(), &mut msg_info)?;
msg_info.print(dir.to_utf8()?)
}

pub fn temp_dir(parent: Option<&Path>, msg_info: &mut MessageInfo) -> cross::Result<PathBuf> {
let parent = match parent {
Some(parent) => parent.to_owned(),
None => util::project_dir(msg_info)?.join("target").join("tmp"),
};
fs::create_dir_all(&parent)?;
let dir = tempfile::TempDir::new_in(&parent)?;
let path = dir.path().to_owned();
mem::drop(dir);

fs::create_dir(&path)?;
Ok(path)
}
Loading

0 comments on commit 8c32d27

Please sign in to comment.