Skip to content

Commit

Permalink
Rewrite the test script as cargo xtask run-tests
Browse files Browse the repository at this point in the history
* Does not require bash to run the script anymore
* This now uses nextest to speedup running tests
* It now offers some additional options like:
  - Running tests only for one backend
  - Filtering tests (by passing additional arguments)
  - Checking the schema.rs files for all examples
  - Running the example tests
* Use the script in CI to ensure that it is still up to date
  • Loading branch information
weiznich committed Aug 2, 2024
1 parent d2dbb0a commit f5d56ae
Show file tree
Hide file tree
Showing 154 changed files with 1,016 additions and 485 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
[alias]
xtask = "run --package xtask --"
19 changes: 19 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
@@ -0,0 1,19 @@
[test-groups]
cli_tests = { max-threads = 8 }

[profile.default.junit]
path = "target/junit.xml"
# These are the default values, specified for clarity.
store-success-output = false
store-failure-output = true

[[profile.default.overrides]]
# these are quite heavy so don't run too much of
# those in parallel
filter = 'package(diesel_cli)'
test-group = 'cli_tests'

[[profile.default.overrides]]
# fails sometimes due to a deadlock
filter = 'test(insert_get_results_batch)'
retries = 2
147 changes: 33 additions & 114 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,14 @@ concurrency:
jobs:
check_and_test:
name: Check
needs: [sqlite_bundled, rustfmt_and_clippy, postgres_bundled, mysql_bundled, typos]
needs:
[
sqlite_bundled,
rustfmt_and_clippy,
postgres_bundled,
mysql_bundled,
typos,
]
strategy:
fail-fast: false
matrix:
Expand All @@ -38,12 45,6 @@ jobs:
with:
key: ${{ runner.os }}-${{ matrix.backend }}-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: Set environment variables
shell: bash
if: matrix.backend == 'mysql'
run: |
echo "RUST_TEST_THREADS=1" >> $GITHUB_ENV
- name: Set environment variables
shell: bash
if: matrix.rust == 'nightly'
Expand All @@ -63,7 64,6 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y libpq-dev postgresql
echo "host all all 127.0.0.1/32 md5" > sudo tee -a /etc/postgresql/10/main/pg_hba.conf
sudo service postgresql restart && sleep 3
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
sudo service postgresql restart && sleep 3
Expand All @@ -73,45 73,12 @@ jobs:
- name: Install sqlite (Linux)
if: runner.os == 'Linux' && matrix.backend == 'sqlite'
run: |
curl -fsS --retry 3 -o sqlite-autoconf-3400100.tar.gz https://www.sqlite.org/2022/sqlite-autoconf-3400100.tar.gz
tar zxf sqlite-autoconf-3400100.tar.gz
cd sqlite-autoconf-3400100
CFLAGS="$CFLAGS -O2 -fno-strict-aliasing \
-DSQLITE_DEFAULT_FOREIGN_KEYS=1 \
-DSQLITE_SECURE_DELETE \
-DSQLITE_ENABLE_COLUMN_METADATA \
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
-DSQLITE_ENABLE_RTREE=1 \
-DSQLITE_SOUNDEX=1 \
-DSQLITE_ENABLE_UNLOCK_NOTIFY \
-DSQLITE_OMIT_LOOKASIDE=1 \
-DSQLITE_ENABLE_DBSTAT_VTAB \
-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1 \
-DSQLITE_ENABLE_LOAD_EXTENSION \
-DSQLITE_ENABLE_JSON1 \
-DSQLITE_LIKE_DOESNT_MATCH_BLOBS \
-DSQLITE_THREADSAFE=1 \
-DSQLITE_ENABLE_FTS3_TOKENIZER=1 \
-DSQLITE_MAX_SCHEMA_RETRY=25 \
-DSQLITE_ENABLE_PREUPDATE_HOOK \
-DSQLITE_ENABLE_SESSION \
-DSQLITE_ENABLE_STMTVTAB \
-DSQLITE_MAX_VARIABLE_NUMBER=250000" \
./configure --prefix=/usr \
--enable-threadsafe \
--enable-dynamic-extensions \
--libdir=/usr/lib/x86_64-linux-gnu \
--libexecdir=/usr/lib/x86_64-linux-gnu/sqlite3
sudo make
sudo make install
echo "SQLITE_DATABASE_URL=/tmp/test.db" >> $GITHUB_ENV
- name: Install mysql (Linux)
if: runner.os == 'Linux' && matrix.backend == 'mysql'
run: |
sudo systemctl start mysql.service
sudo apt-get update
sudo apt-get -y install libmysqlclient-dev
mysql -e "create database diesel_test; create database diesel_unit_test; grant all on \`diesel_%\`.* to 'root'@'localhost';" -uroot -proot
echo "MYSQL_DATABASE_URL=mysql://root:root@localhost/diesel_test" >> $GITHUB_ENV
echo "MYSQL_EXAMPLE_DATABASE_URL=mysql://root:root@localhost/diesel_example" >> $GITHUB_ENV
Expand Down Expand Up @@ -157,7 124,6 @@ jobs:
echo "MYSQLCLIENT_LIB_DIR=/usr/local/opt/[email protected]/lib" >> $GITHUB_ENV
echo "MYSQLCLIENT_VERSION=10.5" >> $GITHUB_ENV
- name: Install mysql (MacOS M1)
if: matrix.os == 'macos-14' && matrix.backend == 'mysql'
run: |
Expand Down Expand Up @@ -229,98 195,51 @@ jobs:
- name: Rust version check
shell: bash
run: |
cargo ${{ matrix.rust }} --version
rustc ${{ matrix.rust }} --version
- name: Test diesel (nightly)
if: matrix.rust == 'nightly'
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel/Cargo.toml --no-default-features --features "${{ matrix.backend }} unstable extras i-implement-a-third-party-backend-and-opt-into-breaking-changes"

- name: Test diesel
if: matrix.rust == 'stable'
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel/Cargo.toml --no-default-features --features "${{ matrix.backend }} extras r2d2"
rustup override set ${{ matrix.rust }}
cargo --version
rustc --version
- name: Test diesel (with-deprecated)
if: matrix.rust == 'beta'
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel/Cargo.toml --no-default-features --features "${{ matrix.backend }} extras with-deprecated"
- uses: taiki-e/install-action@nextest

- name: Test diesel-derives (nightly)
- name: Add Flags (nightly)
if: matrix.rust == 'nightly'
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel_derives/Cargo.toml --no-default-features --features "diesel/${{ matrix.backend }} diesel/unstable diesel/time time diesel/chrono chrono ${{ matrix.backend }}"

- name: Test diesel-derives
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel_derives/Cargo.toml --no-default-features --features "diesel/${{ matrix.backend }} ${{ matrix.backend }}"

- name: Test diesel-cli
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel_cli/Cargo.toml --no-default-features --features "${{ matrix.backend }}"

- name: Test diesel examples
shell: bash
env:
BACKEND: ${{ matrix.backend }}
run: |
(cd examples/${{ matrix.backend }} && rustup run ${{ matrix.rust }} bash test_all)
echo FLAGS="-F diesel/i-implement-a-third-party-backend-and-opt-into-breaking-changes -F diesel/unstable -F diesel/without-deprecated" >> $GITHUB_ENV
- name: Test migrations-internals
- name: Add Flags (beta)
if: matrix.rust == 'beta' && matrix.backend == 'sqlite'
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel_migrations/migrations_internals/Cargo.toml

- name: Test migrations-macros
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel_migrations/migrations_macros/Cargo.toml --features "diesel/${{ matrix.backend }} ${{ matrix.backend }}"

- name: Test table-macro-syntax
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel_table_macro_syntax/Cargo.toml
run: |
echo FLAGS="-F diesel/returning_clauses_for_sqlite_3_35 -F libsqlite3-sys/bundled" >> $GITHUB_ENV
- name: Test diesel_migrations
- name: Add Flags (stable)
if: matrix.rust == 'stable'
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel_migrations/Cargo.toml --features "${{ matrix.backend }} diesel/${{ matrix.backend }}"
run: |
echo FLAGS="-F diesel/with-deprecated" >> $GITHUB_ENV
- name: Run diesel_tests (nightly)
if: matrix.rust == 'nightly'
- name: Skip Doc tests for windows/macos
if: runner.os != 'Linux'
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel_tests/Cargo.toml --no-default-features --features "${{ matrix.backend }} unstable"
run: |
echo NO_DOC_TESTS="--no-doc-tests" >> $GITHUB_ENV
- name: Run diesel_tests (beta)
if: matrix.rust == 'beta'
- name: Enable example schema checks on linux
if: runner.os != 'Linux'
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel_tests/Cargo.toml --no-default-features --features "${{ matrix.backend }} returning_clauses_for_sqlite_3_35 libsqlite3-sys/bundled"

- name: Run diesel_tests
if: matrix.rust == 'stable'
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel_tests/Cargo.toml --no-default-features --features "${{ matrix.backend }}"
run: |
echo EXAMPLE_SCHEMA_CHECKS="--no-example-schema-check" >> $GITHUB_ENV
- name: Run diesel_dynamic_schema tests
- name: Run tests
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel_dynamic_schema/Cargo.toml --no-default-features --features "${{ matrix.backend }} diesel/${{ matrix.backend }}"
run: cargo xtask run-tests ${{ matrix.backend }} $NO_DOC_TESTS $EXAMPLE_SCHEMA_CHECKS -- --no-fail-fast $FLAGS

- name: Run diesel_benches
if: runner.os == 'Linux'
shell: bash
run: cargo ${{ matrix.rust }} test --manifest-path diesel_bench/Cargo.toml --no-default-features --features "${{ matrix.backend }}" --bench benchmarks

- name: Run rustdoc (nightly)
if: matrix.rust == 'nightly'
shell: bash
run: cargo ${{ matrix.rust }} doc --manifest-path diesel/Cargo.toml --no-deps --no-default-features --features "${{ matrix.backend }} unstable i-implement-a-third-party-backend-and-opt-into-breaking-changes extras"

- name: Run rustdoc
if: matrix.rust == 'stable'
shell: bash
run: cargo ${{ matrix.rust }} doc --manifest-path diesel/Cargo.toml --no-deps --no-default-features --features "${{ matrix.backend }}"

- name: Run rustdoc (with-deprecated)
if: matrix.rust == 'beta'
shell: bash
run: cargo ${{ matrix.rust }} doc --manifest-path diesel/Cargo.toml --no-deps --no-default-features --features "${{ matrix.backend }} with-deprecated"

compile_tests:
name: Compiletests
runs-on: ubuntu-latest
Expand Down
15 changes: 9 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 110,10 @@ Thank you! We'll try to respond as quickly as possible.
```

5. Now, try running the test suite to confirm everything works for you locally
by executing `bin/test`. (Initially, this will take a while to compile
by executing `cargo xtask run-tests`. (Initially, this will take a while to compile
everything.) In addition, if you want to compile and test a crate separately,
you can refer to the commands in `bin/test`.
you can refer to the commands printed and executed by `cargo xtask run-tests`. Additionally you
can check `cargo xtask run-tests --help` on how to further configure which tests are executed.

[rustup]: https://rustup.rs/

Expand All @@ -126,17 127,19 @@ To run rustfmt tests locally:

2. Install the rustfmt and clippy by running
```
rustup component add rustfmt-preview
rustup component add clippy-preview
rustup component add rustfmt
rustup component add clippy
```

3. Install [cargo-nextest](https://nexte.st/) via `cargo install cargo-nextest`

3. Run clippy using cargo from the root of your diesel repo.
4. Run clippy using cargo from the root of your diesel repo.
```
cargo clippy --all
```
Each PR needs to compile without warning.

4. Run rustfmt using cargo from the root of your diesel repo.
5. Run rustfmt using cargo from the root of your diesel repo.

To see changes that need to be made, run

Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 28,13 @@ members = [
"examples/sqlite/getting_started_step_1",
"examples/sqlite/getting_started_step_2",
"examples/sqlite/getting_started_step_3",
"examples/sqlite/relations",
"examples/sqlite/relations", "xtask",
]

[workspace.package]
rust-version = "1.78.0"
include = ["src/**/*.rs", "tests/**/*.rs", "LICENSE-*", "README.md"]
edition = "2021"

[workspace.dependencies]
libsqlite3-sys = "0.29"
Expand Down
52 changes: 0 additions & 52 deletions bin/test

This file was deleted.

Loading

0 comments on commit f5d56ae

Please sign in to comment.