Skip to content

Commit

Permalink
Merge pull request #69 from posit-dev/feature/ci
Browse files Browse the repository at this point in the history
Add CI
  • Loading branch information
DavisVaughan authored Nov 27, 2024
2 parents 47fc94c + fc04c12 commit 61d2e71
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
54 changes: 54 additions & 0 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: "Test - linux"

on:
workflow_call:
workflow_dispatch:
inputs:
ssh:
description: 'Set up an SSH session before running `cargo test`?'
type: boolean
required: true
default: false

jobs:
linux:
runs-on: ubuntu-latest
name: "Rust: ${{ matrix.config.rust }}"
strategy:
fail-fast: false
matrix:
config:
- { rust: 'stable' }
- { rust: 'nightly' }
timeout-minutes: 30
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- name: Update build environment
run: |
sudo apt-get update
- name: Install nightly rust
uses: dtolnay/rust-toolchain@nightly
if: matrix.config.rust == 'nightly'

- name: Report rust toolchain
run: rustup show

- name: Rust cache
uses: Swatinem/rust-cache@v2
# Cache isn't useful on nightly, it would be thrown away every day
if: matrix.config.rust != 'nightly'

- name: Setup SSH access
uses: mxschmitt/action-tmate@v3
if: ${{ inputs.ssh }}
timeout-minutes: 30

- name: Build
run: cargo build

- name: Run unit tests
run: cargo test
32 changes: 32 additions & 0 deletions .github/workflows/test-mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Test - mac"

on:
workflow_call:
workflow_dispatch:

jobs:
macos:
runs-on: macos-latest
name: "Rust: ${{ matrix.config.rust }}"
strategy:
fail-fast: false
matrix:
config:
- { rust: 'stable' }
timeout-minutes: 30
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- name: Report rust toolchain
run: rustup show

- name: Rust cache
uses: Swatinem/rust-cache@v2

- name: Build
run: cargo build

- name: Run unit tests
run: cargo test
32 changes: 32 additions & 0 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Test - windows"

on:
workflow_call:
workflow_dispatch:

jobs:
windows:
runs-on: windows-latest
name: "Rust: ${{ matrix.config.rust }}"
strategy:
fail-fast: false
matrix:
config:
- { rust: 'stable' }
timeout-minutes: 30
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- name: Report rust toolchain
run: rustup show

- name: Rust cache
uses: Swatinem/rust-cache@v2

- name: Build
run: cargo build

- name: Run unit tests
run: cargo test
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Test"
on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
test_macos:
name: Test mac
uses: ./.github/workflows/test-mac.yml
secrets: inherit

test_windows:
name: Test windows
uses: ./.github/workflows/test-windows.yml
secrets: inherit

test_linux:
name: Test linux
uses: ./.github/workflows/test-linux.yml
secrets: inherit
5 changes: 3 additions & 2 deletions crates/air_r_formatter/tests/specs/r/value/string_value.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
'hi there!'
'\''
"'"
r"("some raw string
business")"
# TODO: https://github.com/posit-dev/air/issues/74
# r"("some raw string
# business")"
10 changes: 6 additions & 4 deletions crates/air_r_formatter/tests/specs/r/value/string_value.R.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ info: r/value/string_value.R
'hi there!'
'\''
"'"
r"("some raw string
business")"
# TODO: https://github.com/posit-dev/air/issues/74
# r"("some raw string
# business")"
```

Expand All @@ -35,6 +36,7 @@ Line width: 80
'hi there!'
'\''
"'"
r"("some raw string
business")"
# TODO: https://github.com/posit-dev/air/issues/74
# r"("some raw string
# business")"
```
86 changes: 43 additions & 43 deletions crates/tests_macros/README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
# Tests macros

A set of utilities that automatically generate unit tests from files.

## Usage

First argument: glob that will passed to https://github.com/gilnaa/globwalk. Crate's cargo.toml will be the base directory. To pattern format see here: https://git-scm.com/docs/gitignore#_pattern_format
Second argument: method that will be called with full path to each file.

One suggestion to organize tests is to put the macro inside a module.

```rust
mod some_mod {
tests_macros::gen_tests!{"tests/*.{js,json}", run_test}

// input_file and expected_file are full paths
fn run_test(input_file: &str, expected_file: &str) {
println!("{:?} {:?}", input_file, expected_file);
}
}
```

Test name is the "snake case" version of the file name.
this will generate the following for each file:

```rust
#[test]
pub fn somefilename()
{
let test_file = "<crate's cargo.toml full path>/tests/sometest.txt";
let test_expected_file = "<crate's cargo.toml full path>/tests/sometest.expected.txt";
run_test(test_file, test_expected_file);
}
```

## How to run

```
> cargo test // all tests in all crates
> cargo test -p crate-name // all tests of one crate
> cargo test -p crate-name -- some_mod:: // all tests of one crate and one module
> cargo test -p crate-name -- some_mod::somefilename // just one test
```
# Tests macros

A set of utilities that automatically generate unit tests from files.

## Usage

First argument: glob that will passed to https://github.com/gilnaa/globwalk. Crate's cargo.toml will be the base directory. To pattern format see here: https://git-scm.com/docs/gitignore#_pattern_format
Second argument: method that will be called with full path to each file.

One suggestion to organize tests is to put the macro inside a module.

```rust
mod some_mod {
tests_macros::gen_tests!{"tests/*.{js,json}", run_test}

// input_file and expected_file are full paths
fn run_test(input_file: &str, expected_file: &str) {
println!("{:?} {:?}", input_file, expected_file);
}
}
```

Test name is the "snake case" version of the file name.
this will generate the following for each file:

```rust
#[test]
pub fn somefilename()
{
let test_file = "<crate's cargo.toml full path>/tests/sometest.txt";
let test_expected_file = "<crate's cargo.toml full path>/tests/sometest.expected.txt";
run_test(test_file, test_expected_file);
}
```

## How to run

```
> cargo test // all tests in all crates
> cargo test -p crate-name // all tests of one crate
> cargo test -p crate-name -- some_mod:: // all tests of one crate and one module
> cargo test -p crate-name -- some_mod::somefilename // just one test
```

0 comments on commit 61d2e71

Please sign in to comment.