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

5
README.md

@ -26,7 +26,7 @@ In `lib.rs` and any integration test files: @@ -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
example shows the default value for each of the inputs:
example shows the default value for each of the inputs.
```yml
jobs:
@ -61,3 +61,6 @@ jobs: @@ -61,3 +61,6 @@ jobs:
# https://github.com/actions/runner/issues/2058
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: @@ -44,20 +44,24 @@ runs:
- name: Run cargo 3ds test
shell: bash
# 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
# 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: |
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="
docker run --rm
-v ${{ runner.temp }}:${{ runner.temp }}
-v ${{ github.workspace }}/target:/app/target
-v ${{ github.workspace }}:${GITHUB_WORKSPACE}
-v ${mounted_pwd}/target:/app/target
-v ${{ runner.temp }}:${RUNNER_TEMP}
${{ inputs.runner-image }}:latest"
env
cargo 3ds -v test ${{ inputs.args }}
env:
# Ensure that doctests get built into a path which is mounted on the host
# as well as in this container (via the bind mount in the RUNNER command)
TMPDIR: ${{ runner.temp }}
# Make sure doctests are built into the shared tempdir instead of the
# container's /tmp which will be immediately removed
TMPDIR: ${{ env.RUNNER_TEMP }}

17
test-runner/src/lib.rs

@ -48,6 +48,10 @@ pub fn run_socket(tests: &[&TestDescAndFn]) { @@ -48,6 +48,10 @@ pub fn run_socket(tests: &[&TestDescAndFn]) {
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
/// your normal doctest to enable running it with the test runners in this crate.
///
@ -59,22 +63,27 @@ pub fn run_socket(tests: &[&TestDescAndFn]) { @@ -59,22 +63,27 @@ pub fn run_socket(tests: &[&TestDescAndFn]) {
///
/// ## Custom runner
///
#[cfg_attr(not(doctest), doc = "````")]
/// ```no_run
/// test_runner::doctest! { SocketRunner,
/// assert_eq!(2 + 2, 4);
/// }
/// ```
#[cfg_attr(not(doctest), doc = "````")]
///
/// ## `should_panic`
///
#[cfg_attr(not(doctest), doc = "````")]
/// ```should_panic
/// test_runner::doctest! {
/// assert_eq!(2 + 2, 5);
/// }
/// ```
#[cfg_attr(not(doctest), doc = "````")]
///
/// ## Custom `fn main`
///
#[cfg_attr(not(doctest), doc = "````")]
/// ```
/// test_runner::doctest! {
/// fn main() {
@ -82,7 +91,9 @@ pub fn run_socket(tests: &[&TestDescAndFn]) { @@ -82,7 +91,9 @@ pub fn run_socket(tests: &[&TestDescAndFn]) {
/// }
/// }
/// ```
#[cfg_attr(not(doctest), doc = "````")]
///
#[cfg_attr(not(doctest), doc = "````")]
/// ```
/// test_runner::doctest! {
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
@ -91,18 +102,21 @@ pub fn run_socket(tests: &[&TestDescAndFn]) { @@ -91,18 +102,21 @@ pub fn run_socket(tests: &[&TestDescAndFn]) {
/// }
/// }
/// ```
#[cfg_attr(not(doctest), doc = "````")]
///
/// ## Implicit return type
///
/// Note that for the rustdoc preprocessor to understand the return type, the
/// `Ok(())` expression must be written _outside_ the `doctest!` invocation.
///
#[cfg_attr(not(doctest), doc = "````")]
/// ```
/// test_runner::doctest! {
/// assert_eq!(2 + 2, 4);
/// }
/// Ok::<(), std::io::Error>(())
/// ```
#[cfg_attr(not(doctest), doc = "````")]
#[macro_export]
macro_rules! doctest {
($runner:ident, fn main() $(-> $ret:ty)? { $($body:tt)* } ) => {
@ -228,9 +242,6 @@ mod link_fix { @@ -228,9 +242,6 @@ mod link_fix {
}
}
#[cfg(doctest)]
struct Dummy;
#[cfg(test)]
mod tests {
#[test]

Loading…
Cancel
Save