Skip to content

Commit

Permalink
Merge pull request #135 from rust3ds/ci/reusable-actions
Browse files Browse the repository at this point in the history
Use external actions / test runner crate so we can actually run our tests!
  • Loading branch information
ian-h-chamberlain authored Oct 21, 2023
2 parents 1bf09fb + 0ff7cae commit a636722
Show file tree
Hide file tree
Showing 25 changed files with 237 additions and 241 deletions.
46 changes: 0 additions & 46 deletions .github/actions/setup/action.yml

This file was deleted.

63 changes: 40 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@ on:
- master
workflow_dispatch:

env:
# https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
# actions-rust-lang/setup-rust-toolchain sets some default RUSTFLAGS
RUSTFLAGS: ""

jobs:
lint:
strategy:
matrix:
toolchain:
# Run against a "known good" nightly
- nightly-2023-05-31
# Run against a "known good" nightly. Rustc version is 1 day behind the toolchain date
- nightly-2023-06-01
# Check for breakage on latest nightly
- nightly

Expand All @@ -33,11 +27,14 @@ jobs:
- name: Checkout branch
uses: actions/checkout@v2

- uses: ./.github/actions/setup
- uses: rust3ds/test-runner/setup@v1
with:
toolchain: ${{ matrix.toolchain }}

- name: Hide duplicate warnings from lint job
# https://github.com/actions/runner/issues/504
# Removing the matchers won't keep the job from failing if there are errors,
# but will at least declutter pull request annotations (especially for warnings).
- name: Hide duplicate annotations from nightly
if: ${{ matrix.toolchain == 'nightly' }}
run: |
echo "::remove-matcher owner=clippy::"
Expand All @@ -46,18 +43,17 @@ jobs:
- name: Check formatting
run: cargo fmt --all --verbose -- --check

- name: Cargo check
run: cargo 3ds clippy --color=always --verbose --all-targets
# --deny=warnings would be nice, but can easily break CI for new clippy
# lints getting added. I'd also like to use Github's "inline warnings"
# feature, but https://github.com/actions/runner/issues/2341 means we
# can't have both that *and* colored output.
- name: Cargo check ctru-sys (without tests)
run: cargo 3ds clippy --package ctru-sys --color=always --verbose

- name: Cargo check ctru-rs (including tests)
run: cargo 3ds clippy --package ctru-rs --color=always --verbose --all-targets

doctests:
test:
strategy:
matrix:
toolchain:
- nightly-2023-05-31
- nightly-2023-06-01
- nightly
continue-on-error: ${{ matrix.toolchain == 'nightly' }}
runs-on: ubuntu-latest
Expand All @@ -66,15 +62,36 @@ jobs:
- name: Checkout branch
uses: actions/checkout@v2

- uses: ./.github/actions/setup
- uses: rust3ds/test-runner/setup@v1
with:
toolchain: ${{ matrix.toolchain }}

- name: Hide duplicated warnings from lint job
run: echo "::remove-matcher owner=clippy::"

- name: Build doc tests
run: cargo 3ds test --doc --verbose
# This needs to be done separately from running the tests to ensure the
# lib tests' .3dsx is built before the test is run (for romfs). We don't
# really have a good way to build the 3dsx in between the build + test,
# unless cargo-3ds actually runs them as separate commands. See
# https://github.com/rust3ds/cargo-3ds/issues/44 for more details
- name: Build lib and integration tests
run: cargo 3ds test --no-run --tests --package ctru-rs

- name: Run lib and integration tests
uses: rust3ds/test-runner/run-tests@v1
with:
args: --tests --package ctru-rs

# TODO: it would be nice to actually build 3dsx for examples/tests, etc.
# and run it somehow, but exactly how remains to be seen.
- name: Build and run doc tests
uses: rust3ds/test-runner/run-tests@v1
with:
args: --doc --package ctru-rs

- name: Upload citra logs and capture videos
uses: actions/upload-artifact@v3
if: success() || failure() # always run unless the workflow was cancelled
with:
name: citra-logs-${{ matrix.toolchain }}
path: |
target/armv6k-nintendo-3ds/debug/deps/*.txt
target/armv6k-nintendo-3ds/debug/deps/*.webm
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ default-members = ["ctru-rs", "ctru-sys"]
resolver = "2"

[patch.'https://github.com/rust3ds/ctru-rs']
# Make sure all dependencies use the local ctru-sys package
# Make sure all dependencies use the local packages. This is needed for things
# like pthread-3ds that rely on ctru-sys, and test-runner which relies on ctru-rs
ctru-rs = { path = "ctru-rs" }
ctru-sys = { path = "ctru-sys" }
7 changes: 4 additions & 3 deletions ctru-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ widestring = "0.2.2"
toml = "0.5"

[dev-dependencies]
bytemuck = "1.12.3"
cfg-if = "1.0.0"
ferris-says = "0.2.1"
futures = "0.3"
lewton = "0.10.2"
test-runner = { git = "https://github.com/rust3ds/test-runner.git" }
time = "0.3.7"
tokio = { version = "1.16", features = ["rt", "time", "sync", "macros"] }
cfg-if = "1.0.0"
bytemuck = "1.12.3"
lewton = "0.10.2"

[features]
default = ["romfs", "big-stack"]
Expand Down
27 changes: 18 additions & 9 deletions ctru-rs/src/applets/swkbd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ impl SoftwareKeyboard {
///
/// # Example
///
/// ```no_run
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # fn main() {
/// #
/// use ctru::applets::swkbd::{SoftwareKeyboard, Kind};
Expand Down Expand Up @@ -191,7 +192,8 @@ impl SoftwareKeyboard {
///
/// # Example
///
/// ```no_run
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// #
Expand Down Expand Up @@ -235,7 +237,8 @@ impl SoftwareKeyboard {
///
/// # Example
///
/// ```no_run
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// #
Expand Down Expand Up @@ -266,7 +269,8 @@ impl SoftwareKeyboard {
///
/// # Example
///
/// ```no_run
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # fn main() {
/// #
/// use ctru::applets::swkbd::{SoftwareKeyboard, Features};
Expand All @@ -286,7 +290,8 @@ impl SoftwareKeyboard {
///
/// # Example
///
/// ```no_run
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # fn main() {
/// #
/// use ctru::applets::swkbd::{SoftwareKeyboard, ValidInput, Filters};
Expand All @@ -309,7 +314,8 @@ impl SoftwareKeyboard {
///
/// # Example
///
/// ```no_run
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # fn main() {
/// #
/// use ctru::applets::swkbd::{SoftwareKeyboard, ValidInput, Filters};
Expand All @@ -336,7 +342,8 @@ impl SoftwareKeyboard {
///
/// # Example
///
/// ```no_run
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # fn main() {
/// #
/// use ctru::applets::swkbd::SoftwareKeyboard;
Expand All @@ -363,7 +370,8 @@ impl SoftwareKeyboard {
///
/// # Example
///
/// ```no_run
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # fn main() {
/// #
/// use ctru::applets::swkbd::{SoftwareKeyboard, Button, Kind};
Expand Down Expand Up @@ -402,7 +410,8 @@ impl SoftwareKeyboard {
///
/// # Example
///
/// ```no_run
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # fn main() {
/// #
/// use ctru::applets::swkbd::{SoftwareKeyboard, Button, Kind};
Expand Down
11 changes: 7 additions & 4 deletions ctru-rs/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ impl<'screen> Console<'screen> {
///
/// # Example
///
/// ```no_run
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// #
/// use ctru::services::gfx::Gfx;
/// use ctru::console::Console;
/// use ctru::services::gfx::Gfx;
///
/// // Initialize graphics.
/// let gfx = Gfx::new()?;
Expand Down Expand Up @@ -94,7 +95,8 @@ impl<'screen> Console<'screen> {
///
/// # Example
///
/// ```no_run
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// #
Expand Down Expand Up @@ -131,7 +133,8 @@ impl<'screen> Console<'screen> {
///
/// # Example
///
/// ```no_run
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// #
Expand Down
5 changes: 3 additions & 2 deletions ctru-rs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ pub type Result<T> = ::std::result::Result<T, Error>;
///
/// # Example
///
/// ```no_run
/// ```
/// use ctru::error::{Result, ResultCode};
///
/// pub fn hid_init() -> Result<()> {
/// pub fn main() -> Result<()> {
/// # let _runner = test_runner::GdbRunner::default();
/// // We run an unsafe function which returns a `ctru_sys::Result`.
/// let result: ctru_sys::Result = unsafe { ctru_sys::hidInit() };
///
Expand Down
12 changes: 6 additions & 6 deletions ctru-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
#![crate_type = "rlib"]
#![crate_name = "ctru"]
#![warn(missing_docs)]
#![feature(test)]
#![feature(custom_test_frameworks)]
#![feature(try_trait_v2)]
#![feature(allocator_api)]
#![test_runner(test_runner::run)]
#![test_runner(test_runner::run_gdb)] // TODO: does this make sense to have configurable?
#![doc(
html_favicon_url = "https://user-images.githubusercontent.com/11131775/225929072-2fa1741c-93ae-4b47-9bdf-af70f3d59910.png"
)]
Expand All @@ -40,7 +39,11 @@ extern crate shim_3ds;
///
/// This value was chosen to support crate dependencies which expected more stack than provided. It's suggested to use less stack if possible.
#[no_mangle]
#[cfg(feature = "big-stack")]
// When building lib tests, we don't want to redefine the same symbol twice,
// since ctru-rs is both the crate under test and a dev-dependency (non-test).
// We might also be able to use #[linkage] for similar effect, but this way
// works without depending on another unstable feature.
#[cfg(all(feature = "big-stack", not(test)))]
static __stacksize__: usize = 2 * 1024 * 1024; // 2MB

macro_rules! from_impl {
Expand Down Expand Up @@ -111,7 +114,4 @@ pub mod os;
pub mod prelude;
pub mod services;

#[cfg(test)]
mod test_runner;

pub use crate::error::{Error, Result};
6 changes: 3 additions & 3 deletions ctru-rs/src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
///
/// # Example
/// ```
/// # // let _runner = test_runner::GdbRunner::default();
/// # let _runner = test_runner::GdbRunner::default();
/// let firm_version = ctru::os::firm_version();
/// assert_ne!(firm_version.major(), 0);
///
Expand Down Expand Up @@ -61,7 +61,7 @@ pub fn kernel_version() -> Version {
///
/// # Example
/// ```
/// # // let _runner = test_runner::GdbRunner::default();
/// # let _runner = test_runner::GdbRunner::default();
/// let all_memory = ctru::os::MemRegion::All;
///
/// assert!(all_memory.size() > 0);
Expand Down Expand Up @@ -111,7 +111,7 @@ impl MemRegion {
/// # Example
///
/// ```
/// # // let _runner = test_runner::GdbRunner::default();
/// let _runner = test_runner::GdbRunner::default();
/// let strength = ctru::os::WifiStrength::current();
/// assert!((strength as u8) < 4);
/// ```
Expand Down
Loading

0 comments on commit a636722

Please sign in to comment.