Skip to content

Commit 8c32d27

Browse files
committed
Initial version of UI tests.
1 parent 35a1e17 commit 8c32d27

File tree

7 files changed

+549
-1
lines changed

7 files changed

+549
-1
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ci/test-ui.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC1091
3+
4+
set -eo pipefail
5+
6+
ci_dir=$(dirname "${BASH_SOURCE[0]}")
7+
ci_dir=$(realpath "${ci_dir}")
8+
. "${ci_dir}"/shared.sh
9+
10+
if [[ -z "${TARGET}" ]]; then
11+
export TARGET="x86_64-unknown-linux-gnu"
12+
fi
13+
14+
cargo xtask ui-test \
15+
--target "${TARGET}" \
16+
--engine "${CROSS_ENGINE}" \
17+
--verbose

src/cli.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn fmt_subcommands(stdout: &str, msg_info: &mut MessageInfo) -> Result<()> {
5454
}
5555
if !host.is_empty() {
5656
msg_info.print("Host Commands:")?;
57-
for line in &cross {
57+
for line in &host {
5858
msg_info.print(line)?;
5959
}
6060
}

xtask/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ once_cell = "1.15"
2323
semver = "1"
2424
chrono = "0.4"
2525
wildmatch = "2.1.1"
26+
tempfile = "3.3.0"

xtask/src/main.rs

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ pub mod crosstool;
88
pub mod hooks;
99
pub mod install_git_hooks;
1010
pub mod target_info;
11+
pub mod temp;
12+
pub mod ui;
1113
pub mod util;
1214

1315
use ci::CiJob;
@@ -23,6 +25,8 @@ use self::crosstool::ConfigureCrosstool;
2325
use self::hooks::{Check, Test};
2426
use self::install_git_hooks::InstallGitHooks;
2527
use self::target_info::TargetInfo;
28+
use self::temp::MakeTempDir;
29+
use self::ui::UiTest;
2630

2731
#[derive(Parser, Debug)]
2832
#[clap(version, about, long_about = None)]
@@ -65,6 +69,10 @@ enum Commands {
6569
ValidateChangelog(ValidateChangelog),
6670
/// Code generation
6771
Codegen(Codegen),
72+
/// Create temporary directory
73+
MakeTempDir(MakeTempDir),
74+
/// Run user-interface suite.
75+
UiTest(UiTest),
6876
}
6977

7078
fn is_toolchain(toolchain: &str) -> cross::Result<String> {
@@ -131,6 +139,12 @@ pub fn main() -> cross::Result<()> {
131139
changelog::validate_changelog(args, &mut msg_info)?;
132140
}
133141
Commands::Codegen(args) => codegen::codegen(args)?,
142+
Commands::MakeTempDir(args) => temp::make_temp_dir(args)?,
143+
Commands::UiTest(args) => {
144+
let mut msg_info = get_msg_info!(args, args.verbose)?;
145+
let engine = get_engine!(args, msg_info)?;
146+
ui::ui_test(args, &engine, &mut msg_info)?
147+
}
134148
}
135149

136150
Ok(())

xtask/src/temp.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::path::{Path, PathBuf};
2+
use std::{fs, mem};
3+
4+
use crate::util;
5+
use clap::Args;
6+
use cross::shell::MessageInfo;
7+
use cross::ToUtf8;
8+
9+
/// Create and print a temporary directory to stdout.
10+
#[derive(Args, Debug)]
11+
pub struct MakeTempDir {
12+
/// `tmp` to create the temporary directory inside.
13+
/// Defaults to `"${target_dir}/tmp"`.
14+
tmpdir: Option<PathBuf>,
15+
}
16+
17+
pub fn make_temp_dir(MakeTempDir { tmpdir }: MakeTempDir) -> cross::Result<()> {
18+
let mut msg_info = MessageInfo::create(0, false, None)?;
19+
let dir = temp_dir(tmpdir.as_deref(), &mut msg_info)?;
20+
msg_info.print(dir.to_utf8()?)
21+
}
22+
23+
pub fn temp_dir(parent: Option<&Path>, msg_info: &mut MessageInfo) -> cross::Result<PathBuf> {
24+
let parent = match parent {
25+
Some(parent) => parent.to_owned(),
26+
None => util::project_dir(msg_info)?.join("target").join("tmp"),
27+
};
28+
fs::create_dir_all(&parent)?;
29+
let dir = tempfile::TempDir::new_in(&parent)?;
30+
let path = dir.path().to_owned();
31+
mem::drop(dir);
32+
33+
fs::create_dir(&path)?;
34+
Ok(path)
35+
}

0 commit comments

Comments
 (0)