Skip to content

Commit

Permalink
build: Use a feature for integration tests (#2899)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Jun 21, 2023
1 parent d5d5362 commit d78dc0b
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 158 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test-all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ jobs:
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo tarpaulin --skip-clean --all-targets --out=Xml
- run:
cargo tarpaulin --skip-clean --all-targets --features=test-dbs
--out=Xml
- name: Upload to codecov.io
uses: codecov/codecov-action@v3
- name: Upload code coverage results
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test-rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ jobs:
command: test
args:
"--no-run --locked --target=${{ inputs.target }} ${{ inputs.target
== 'x86_64-unknown-linux-gnu' && '--features=test-external-dbs' ||
'' }}"
== 'x86_64-unknown-linux-gnu' && '--features=test-dbs-external' ||
'--features=test-dbs' }}"
- name: Run docker compose
run: docker compose up -d
working-directory: ./prql-compiler/tests/integration
Expand All @@ -82,9 +82,9 @@ jobs:
command: insta
# Autoformatting doesn't make this clear to read, but this tertiary
# expression states to only check these on ubuntu linux:
# - External DB integration tests — `--features=test-external-dbs`.
# - External DB integration tests — `--features=test-dbs-external`.
# - Unreferenced snapshots - `--unreferenced=auto`.
args:
test --target=${{ inputs.target }} ${{ inputs.target==
'x86_64-unknown-linux-gnu' && '--unreferenced=auto
--features=test-external-dbs' || '' }}
--features=test-dbs-external' || '--features=test-dbs' }}
10 changes: 2 additions & 8 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,9 @@ tasks:
# - "**/*.snap"
cmds:
# Only delete unreferenced snapshots on the default target — lots are
# excluded under wasm. Note that this will also over-delete on Windows.
- cargo insta test --accept --unreferenced=auto
# excluded under wasm.
- cargo insta test --accept --features=test-dbs --unreferenced=auto
- cargo insta test --accept --target=wasm32-unknown-unknown
# We build the book too, because that acts as a test
- cd web/book && mdbook build

test-rust-fast:
desc: Test prql-compiler's unit tests.
Expand All @@ -232,10 +230,6 @@ tasks:
RUST_BACKTRACE: 1
sources:
# I don't think we can specify this is a single glob, which would be nice.
# Ideally we want to exclude `.pending-snap` & `.snap.new` files so runs
# doesn't cause an infinite loop of other runs (though possibly mitigated
# by `--accept` and task not interrupting existing runs, so all files go
# to `.snap`s which match the generated output?).
- "prql-compiler/**/*.rs"
- "prql-compiler/**/*.snap"
cmds:
Expand Down
4 changes: 2 additions & 2 deletions bacon.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ default_job = "clippy"

# PRQL additions
[jobs.test]
command = ['cargo', 'insta', 'test', "--color=always", "--unreferenced=auto"]
command = ['cargo', 'insta', 'test', "--color=always", "--features=test-dbs", "--unreferenced=auto"]

[jobs.test-accept]
command = ['cargo', 'insta', 'test', '--accept', "--color=always", "--unreferenced=auto"]
command = ['cargo', 'insta', 'test', '--accept', "--color=always", "--features=test-dbs", "--unreferenced=auto"]
watch = ["*"]

[jobs.test-accept-fast]
Expand Down
40 changes: 23 additions & 17 deletions prql-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ version.workspace = true

metadata.msrv = "1.65.0"

[features]
default = []
# Technically tokio could be limited to external tests, but its types are in
# signatures which would require lots of conditional compilation.
test-dbs = ["duckdb", "rusqlite", "tokio"]
test-dbs-external = ["chrono", "duckdb", "mysql", "pg_bigdecimal", "postgres", "rusqlite", "tiberius", "tokio", "tokio-util"]

[dependencies]
anstream = {version = "0.3.2", features = ["auto"]}
anyhow = {version = "1.0.57", features = ["backtrace"]}
Expand All @@ -34,29 +41,31 @@ strum_macros = "0.25.0"
# Chumsky's default features have issues when running in wasm (though we only
# see it when compiling on MacOS), so we only include features when running
# outside wasm.
[target.'cfg(not(target_family="wasm"))'.dependencies]
chumsky = "0.9.2"
[target.'cfg(target_family="wasm")'.dependencies]
chumsky = {version = "0.9.2", features = ["ahash", "std"], default-features = false}

[target.'cfg(not(target_family="wasm"))'.dependencies]
# For integration tests. These are not listed as dev-dependencies because
# dev-dependencies can't be optional.
chrono = {version = "0.4", optional = true, features = [], default-features = false}
duckdb = {version = "0.8.0", optional = true, features = ["bundled", "chrono"]}
mysql = {version = "24", optional = true}
pg_bigdecimal = {version = "0.1", optional = true}
postgres = {version = "0.19", optional = true}
rusqlite = {version = "0.29.0", optional = true, features = ["bundled", "csvtab"]}
tiberius = {version = "0.12", optional = true, features = ["sql-browser-tokio", "bigdecimal", "time"]}
tokio = {version = "1", optional = true, features = ["full"]}
tokio-util = {version = "0.7", optional = true, features = ["compat"]}
# Default chumsky features outside wasm.
chumsky = "0.9.2"

[dev-dependencies]
cfg-if = "1.0"
insta = {version = "1.29", features = ["colors", "glob", "yaml"]}
similar-asserts = "1.4.2"

# For integration tests
[target.'cfg(not(target_family="wasm"))'.dev-dependencies]
chrono = {version = "0.4", features = [], default-features = false}
criterion = "0.5.1"
csv = "1.2"
duckdb = {version = "0.8.0", features = ["bundled", "chrono"]}
mysql = "24"
pg_bigdecimal = "0.1"
postgres = "0.19"
rusqlite = {version = "0.29.0", features = ["bundled", "csvtab"]}
tiberius = {version = "0.12", features = ["sql-browser-tokio", "bigdecimal", "time"]}
tokio = {version = "1", features = ["full"]}
tokio-util = {version = "0.7", features = ["compat"]}
criterion = {version = "0.5.1"}

[[bench]]
harness = false
Expand Down Expand Up @@ -115,6 +124,3 @@ exactly = 1
file = "../.github/actions/build-prqlc/action.yaml"
replace = 'prefix-key: {{version}}'
search = 'prefix-key: [\d.]+'

[features]
test-external-dbs = []
4 changes: 2 additions & 2 deletions prql-compiler/tests/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ cargo build.
### External DBs

These will not run as a part of `cargo test`. Use
`cargo test --features=test-external-dbs` instead. Make sure to start docker
`cargo test --features=test-dbs-external` instead. Make sure to start docker
compose before (see below).

Currently Postgres, MySQL, SQL Server and ClickHouse are tested.
Expand All @@ -66,7 +66,7 @@ Steps to run the tests:
2. Run the tests:

```sh
cargo test --features=test-external-dbs
cargo test --features=test-dbs-external
```

## Test organization
Expand Down
Loading

0 comments on commit d78dc0b

Please sign in to comment.