Skip to content

Commit

Permalink
Merge pull request #134 from rami3l/test
Browse files Browse the repository at this point in the history
test(dsl): use system shell as dsl backend
  • Loading branch information
rami3l authored Jul 2, 2021
2 parents 415edfa + bb291cc commit aa4e50a
Show file tree
Hide file tree
Showing 26 changed files with 908 additions and 220 deletions.
146 changes: 98 additions & 48 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,6 @@ on:
- master

jobs:
asi-build-test:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: aarch64-apple-darwin
override: true

- name: Set macOS environment variables
# if: runner.os == 'macOS'
run: |
echo "SDKROOT=$(xcrun -sdk macosx11.1 --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.1 --show-sdk-platform-version)" >> $GITHUB_ENV
- name: Build
run: cargo build --verbose --release --locked --target=aarch64-apple-darwin

musl-build-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: x86_64-unknown-linux-musl
override: true

- name: Build
run: cargo build --verbose --release --locked --target=x86_64-unknown-linux-musl

choco-test:
runs-on: windows-latest
steps:
Expand All @@ -52,10 +18,12 @@ jobs:
override: true
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test chocolatey --verbose
- name: Run unit tests
run: cargo test tests --verbose
- name: Run smoke tests
run: cargo test choco --verbose
- name: Run heavy tests
run: cargo test chocolatey --verbose -- --ignored
run: cargo test choco --verbose -- --ignored

scoop-test:
runs-on: windows-latest
Expand All @@ -73,40 +41,78 @@ jobs:
Get-Command scoop
- name: Build
run: cargo build --verbose
- name: Run tests
- name: Run unit tests
run: cargo test tests --verbose
- name: Run smoke tests
run: cargo test scoop --verbose
- name: Run heavy tests
run: cargo test scoop --verbose -- --ignored

homebrew-test:
brew-test:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: aarch64-apple-darwin
override: true
- name: Set macOS environment variables
# if: runner.os == 'macOS'
run: |
echo "SDKROOT=$(xcrun -sdk macosx11.1 --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.1 --show-sdk-platform-version)" >> $GITHUB_ENV
- name: Test build for aarch64
run: cargo build --verbose --release --locked --target=aarch64-apple-darwin
- name: Test native Build
run: cargo build --verbose
# - run: brew list
- name: Run unit tests
run: cargo test tests --verbose
- name: Run smoke tests
run: cargo test brew --verbose
- name: Run heavy tests
run: cargo test brew --verbose -- --ignored

port-test:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Install MacPorts
run: |
curl -LO https://raw.githubusercontent.com/GiovanniBussi/macports-ci/master/macports-ci
source ./macports-ci install
sudo port install wget
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test homebrew --verbose
- run: port installed
- name: Run unit tests
run: cargo test tests --verbose
- name: Run smoke tests
run: cargo test port --verbose
- name: Run heavy tests
run: cargo test homebrew --verbose -- --ignored
run: cargo test port --verbose -- --ignored

apt-test:
runs-on: ubuntu-latest
container:
image: docker://rust:latest
steps:
- uses: actions/checkout@v2
- run: apt-get update && apt-get install -y curl build-essential
# - run: apt-get update && apt-get install -y curl build-essential
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: x86_64-unknown-linux-musl
override: true
- name: Build
- name: Test build for musl
run: cargo build --verbose --release --locked --target=x86_64-unknown-linux-musl
- name: Test native Build
run: cargo build --verbose
- name: Run unit tests
run: cargo test tests --verbose
Expand All @@ -118,7 +124,7 @@ jobs:
dnf-test:
runs-on: ubuntu-latest
container:
image: docker://fedora:latest
image: fedora:latest
steps:
- uses: actions/checkout@v2
- run: dnf install -y make automake gcc gcc-c++ kernel-devel
Expand All @@ -136,6 +142,28 @@ jobs:
- name: Run heavy tests
run: cargo test dnf --verbose -- --ignored

emerge-test:
runs-on: ubuntu-latest
container:
image: gentoo/stage3
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
# `pacaptr -Ss` might fail without this line.
- run: emerge --sync || true
- name: Build
run: cargo build --verbose
- name: Run unit tests
run: cargo test tests --verbose
- name: Run smoke tests
run: cargo test emerge --verbose
- name: Run heavy tests
run: cargo test emerge --verbose -- --ignored

zypper-test:
runs-on: ubuntu-latest
container:
Expand All @@ -161,7 +189,7 @@ jobs:
apk-test:
runs-on: ubuntu-latest
container:
image: docker://rust:alpine
image: rust:alpine
env:
RUSTFLAGS: "-C target-feature=-crt-static"
steps:
Expand All @@ -180,3 +208,25 @@ jobs:
run: cargo test apk --verbose
- name: Run heavy tests
run: cargo test apk --verbose -- --ignored

pip-conda-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Build
run: cargo build --verbose
# - name: Run unit tests
# run: cargo test tests --verbose
- name: Run smoke tests
run: |
cargo test pip --verbose
cargo test conda --verbose
- name: Run heavy tests
run: |
cargo test pip --verbose -- --ignored
cargo test conda --verbose -- --ignored
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"cSpell.words": [
"Bohnenkamper",
"Exherbo",
"Pkgng",
"SDKROOT",
"Swupd",
"Tazpkg",
"Tlmgr",
"Unmerging",
"Zypper",
"aarch",
"algos",
Expand All @@ -28,6 +30,7 @@
"impls",
"indoc",
"itertools",
"libzypp",
"litrs",
"macos",
"mockpm",
Expand All @@ -53,7 +56,9 @@
"structopt",
"subcmd",
"svenstaro",
"sympy",
"sysupgrade",
"unmerge",
"untrusted",
"verif",
"xcrun",
Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion docs/compatibility_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
conda.rs * * * * * * * * *
dnf.rs * * * * * * * * * * * * * * * * * * * * * * * * *
emerge.rs * * * * * * * * * * * * * * * *
pip.rs * * * * * * * * * *
pip.rs * * * * * * * * *
port.rs * * * * * * * * * * * * * * * * *
scoop.rs * * * * * * * * * * * * * *
tlmgr.rs * * * * * * * * * * * *
Expand Down
29 changes: 28 additions & 1 deletion pacaptr-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
mod test_dsl;

use crate::test_dsl::test_dsl_impl;
use itertools::Itertools;
use litrs::StringLit;
use proc_macro2::TokenStream;
use quote::quote;
use std::convert::TryFrom;

/// A DSL (Domain-Specific Language) embedded in Rust, in order to simplify the form of smoke tests.
///
/// This macro accepts the source of the Test DSL in a **string literal**.
/// In this DSL, each line is called an `item`. We now support the following item types:
/// - `in` item: Run command on `pacaptr`.
/// - `in !` item: Run command with the system shell (`sh` on Unix,`powershell` on Windows).
/// - `ou` item: Check the output of the **last** `in` or `in !` item above against a **regex** pattern.
///
/// # Examples
///
/// ```no_run
/// #[test]
/// #[ignore]
/// fn apt_r_s() {
/// test_dsl! { r##"
/// in -Sy # Refresh with `pacaptr -Sy`.
/// in -S screen --yes # Install `screen`.
/// in ! which screen # Verify installation.
/// ou ^/usr/bin/screen
///
/// in -R screen --yes # Remove `screen`.
/// in -Qi screen # Verify removal.
/// ou ^Status: deinstall
/// "## }
/// }
/// ```
#[proc_macro]
pub fn test_dsl(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = TokenStream::from(input);

let input = input.into_iter().collect::<Vec<_>>();
let input = input.into_iter().collect_vec();
if input.len() != 1 {
let msg = format!(
"argument must be a single string literal, but got {} tokens",
Expand Down
9 changes: 6 additions & 3 deletions pacaptr-macros/src/test_dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use proc_macro2::{Literal, Span, TokenStream};
use quote::quote;
use syn::{Error, Result};

// ! TODO: Implement pipe with Rust.
enum TestDslItem {
Im(Vec<String>),
In(Vec<String>),
Expand All @@ -28,8 +27,12 @@ impl TestDslItem {
Ok(TestDslItem::Ou(rest.into()))
} else {
let msg = format!(
"Item must start with `{}`/`{}`/`{}`/`{}`, found `{}`",
in_bang, in_, ou, im, ln,
"Item must start with one of the following: {}, found `{}`",
[in_bang, in_, ou, im]
.iter()
.map(|&s| format!("`{}`", s.trim_start()))
.join(", "),
ln,
);
Err(Error::new(Span::call_site(), msg))
}
Expand Down
4 changes: 2 additions & 2 deletions src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,13 @@ pub fn prompt(question: &str, options: &str, expected: &[&str], case_sensitive:
/// Finds all lines in the given `text` that matches all the `patterns`.
///
/// We suppose that all patterns are legal regular expressions.
/// An error message will be printed if this is not the case.
/// An error message will be returned if this is not the case.
pub fn grep<'t>(text: &'t str, patterns: &[&str]) -> Result<Vec<&'t str>> {
patterns
.iter()
.map(|&pat| {
Regex::new(pat)
.map_err(|_e| Error::OtherError(format!("Pattern `{}` is ill-formed.", pat)))
.map_err(|_e| Error::OtherError(format!("Pattern `{}` is ill-formed", pat)))
})
.try_collect()
.map(|rs: Vec<Regex>| {
Expand Down
2 changes: 1 addition & 1 deletion src/pm/apt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl Pm for Apt {
Cmd::with_sudo(&["apt", "install", "--download-only"])
.kws(kws)
.flags(flags)
.pipe(|cmd| self.run(cmd))
.pipe(|cmd| self.run_with(cmd, Default::default(), &STRAT_INSTALL))
.await
}

Expand Down
Loading

0 comments on commit aa4e50a

Please sign in to comment.