Browse Source

Use runner.temp for doctest artifacts

pull/9/head
Ian Chamberlain 1 year ago
parent
commit
b58a9bbf04
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 10
      .github/workflows/ci.yml
  2. 5
      README.md
  3. 18
      run-tests/action.yml
  4. 17
      test-runner/src/lib.rs

10
.github/workflows/ci.yml

@ -67,9 +67,9 @@ jobs:
# Still run doc tests even if lib/integration tests fail: # Still run doc tests even if lib/integration tests fail:
if: ${{ !cancelled() }} if: ${{ !cancelled() }}
env: env:
# This ensures the citra logs and video output get put in a directory where the # This ensures the citra logs and video output get persisted to a
# artifact upload can find them (instead of being removed from the tmpdir) # directory where the artifact upload can find them.
RUSTDOCFLAGS: " --persist-doctests ${{ env.GITHUB_WORKSPACE }}/target/armv6k-nintendo-3ds/debug/doctests" RUSTDOCFLAGS: " --persist-doctests target/armv6k-nintendo-3ds/debug/doctests"
uses: ./run-tests uses: ./run-tests
with: with:
working-directory: test-runner working-directory: test-runner
@ -82,5 +82,5 @@ jobs:
with: with:
name: citra-logs-${{ matrix.toolchain }} name: citra-logs-${{ matrix.toolchain }}
path: | path: |
target/armv6k-nintendo-3ds/debug/**/*.txt test-runner/target/armv6k-nintendo-3ds/debug/**/*.txt
target/armv6k-nintendo-3ds/debug/**/*.webm test-runner/target/armv6k-nintendo-3ds/debug/**/*.webm

5
README.md

@ -26,7 +26,7 @@ In `lib.rs` and any integration test files:
``` ```
Then use the `setup` and `run-tests` actions in your github workflow. This Then use the `setup` and `run-tests` actions in your github workflow. This
example shows the default value for each of the inputs: example shows the default value for each of the inputs.
```yml ```yml
jobs: jobs:
@ -61,3 +61,6 @@ jobs:
# https://github.com/actions/runner/issues/2058 # https://github.com/actions/runner/issues/2058
working-directory: ${GITHUB_WORKSPACE} working-directory: ${GITHUB_WORKSPACE}
``` ```
See [`ci.yml`](.github/workflows/ci.yml) to see a full lint and test workflow
using these actions (including uploading output artifacts from the tests).

18
run-tests/action.yml

@ -44,20 +44,24 @@ runs:
- name: Run cargo 3ds test - name: Run cargo 3ds test
shell: bash shell: bash
# Set a custom runner for `cargo test` commands to use. # Set a custom runner for `cargo test` commands to use.
# Use ${GITHUB_WORKSPACE} due to # Use ${PWD} and ${RUNNER_TEMP} due to
# https://github.com/actions/runner/issues/2058, which also means # https://github.com/actions/runner/issues/2058, which also means
# we have to export this instead of using the env: key # we have to export this in `run` instead of using the `env` key
run: | run: |
cd ${{ inputs.working-directory }} cd ${{ inputs.working-directory }}
# Hopefully this still works if the input is an absolute path:
mounted_pwd="${{ github.workspace }}/${{ inputs.working-directory }}"
export CARGO_TARGET_ARMV6K_NINTENDO_3DS_RUNNER=" export CARGO_TARGET_ARMV6K_NINTENDO_3DS_RUNNER="
docker run --rm docker run --rm
-v ${{ runner.temp }}:${{ runner.temp }}
-v ${{ github.workspace }}/target:/app/target
-v ${{ github.workspace }}:${GITHUB_WORKSPACE} -v ${{ github.workspace }}:${GITHUB_WORKSPACE}
-v ${mounted_pwd}/target:/app/target
-v ${{ runner.temp }}:${RUNNER_TEMP}
${{ inputs.runner-image }}:latest" ${{ inputs.runner-image }}:latest"
env env
cargo 3ds -v test ${{ inputs.args }} cargo 3ds -v test ${{ inputs.args }}
env: env:
# Ensure that doctests get built into a path which is mounted on the host # Make sure doctests are built into the shared tempdir instead of the
# as well as in this container (via the bind mount in the RUNNER command) # container's /tmp which will be immediately removed
TMPDIR: ${{ runner.temp }} TMPDIR: ${{ env.RUNNER_TEMP }}

17
test-runner/src/lib.rs

@ -48,6 +48,10 @@ pub fn run_socket(tests: &[&TestDescAndFn]) {
run::<SocketRunner>(tests); run::<SocketRunner>(tests);
} }
// Use a neat little trick with cfg(doctest) to make code fences appear in
// rustdoc output, but still compile normally when doctesting. This raises warnings
// for invalid code though, so we also silence that lint here.
#[cfg_attr(not(doctest), allow(rustdoc::invalid_rust_codeblocks))]
/// Helper macro for writing doctests using this runner. Wrap this macro around /// Helper macro for writing doctests using this runner. Wrap this macro around
/// your normal doctest to enable running it with the test runners in this crate. /// your normal doctest to enable running it with the test runners in this crate.
/// ///
@ -59,22 +63,27 @@ pub fn run_socket(tests: &[&TestDescAndFn]) {
/// ///
/// ## Custom runner /// ## Custom runner
/// ///
#[cfg_attr(not(doctest), doc = "````")]
/// ```no_run /// ```no_run
/// test_runner::doctest! { SocketRunner, /// test_runner::doctest! { SocketRunner,
/// assert_eq!(2 + 2, 4); /// assert_eq!(2 + 2, 4);
/// } /// }
/// ``` /// ```
#[cfg_attr(not(doctest), doc = "````")]
/// ///
/// ## `should_panic` /// ## `should_panic`
/// ///
#[cfg_attr(not(doctest), doc = "````")]
/// ```should_panic /// ```should_panic
/// test_runner::doctest! { /// test_runner::doctest! {
/// assert_eq!(2 + 2, 5); /// assert_eq!(2 + 2, 5);
/// } /// }
/// ``` /// ```
#[cfg_attr(not(doctest), doc = "````")]
/// ///
/// ## Custom `fn main` /// ## Custom `fn main`
/// ///
#[cfg_attr(not(doctest), doc = "````")]
/// ``` /// ```
/// test_runner::doctest! { /// test_runner::doctest! {
/// fn main() { /// fn main() {
@ -82,7 +91,9 @@ pub fn run_socket(tests: &[&TestDescAndFn]) {
/// } /// }
/// } /// }
/// ``` /// ```
#[cfg_attr(not(doctest), doc = "````")]
/// ///
#[cfg_attr(not(doctest), doc = "````")]
/// ``` /// ```
/// test_runner::doctest! { /// test_runner::doctest! {
/// fn main() -> Result<(), Box<dyn std::error::Error>> { /// fn main() -> Result<(), Box<dyn std::error::Error>> {
@ -91,18 +102,21 @@ pub fn run_socket(tests: &[&TestDescAndFn]) {
/// } /// }
/// } /// }
/// ``` /// ```
#[cfg_attr(not(doctest), doc = "````")]
/// ///
/// ## Implicit return type /// ## Implicit return type
/// ///
/// Note that for the rustdoc preprocessor to understand the return type, the /// Note that for the rustdoc preprocessor to understand the return type, the
/// `Ok(())` expression must be written _outside_ the `doctest!` invocation. /// `Ok(())` expression must be written _outside_ the `doctest!` invocation.
/// ///
#[cfg_attr(not(doctest), doc = "````")]
/// ``` /// ```
/// test_runner::doctest! { /// test_runner::doctest! {
/// assert_eq!(2 + 2, 4); /// assert_eq!(2 + 2, 4);
/// } /// }
/// Ok::<(), std::io::Error>(()) /// Ok::<(), std::io::Error>(())
/// ``` /// ```
#[cfg_attr(not(doctest), doc = "````")]
#[macro_export] #[macro_export]
macro_rules! doctest { macro_rules! doctest {
($runner:ident, fn main() $(-> $ret:ty)? { $($body:tt)* } ) => { ($runner:ident, fn main() $(-> $ret:ty)? { $($body:tt)* } ) => {
@ -228,9 +242,6 @@ mod link_fix {
} }
} }
#[cfg(doctest)]
struct Dummy;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[test] #[test]

Loading…
Cancel
Save