Skip to content

Commit 4101d74

Browse files
authored
test: combine a few more tests (#3722)
1 parent 1c0bc73 commit 4101d74

File tree

18 files changed

+54
-82
lines changed

18 files changed

+54
-82
lines changed

Cargo.lock

Lines changed: 1 addition & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ members = [
66
"prqlc/prql-compiler-macros",
77
"prqlc/prqlc",
88
"prqlc/prql-compiler/examples/compile-files", # An example
9-
"prqlc/tests_misc",
109
"prqlc/bindings/elixir/native/prql",
1110
"prqlc/bindings/java",
1211
"prqlc/bindings/js",

justfile

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,28 @@ fmt:
1616
--config=.prettierrc.yaml \
1717
--ignore-path=.prettierignore \
1818
--ignore-unknown \
19-
--log-level=warn
19+
--log-level=warn &
2020

2121

2222
prqlc-lint:
2323
@echo '--- clippy ---'
2424
@cargo clippy --all --fix --allow-staged
2525

2626

27-
target := 'x86_64-unknown-linux-gnu'
28-
2927
# Test prqlc
30-
prqlc-test:
31-
@echo "Testing prqlc…"
28+
packages := '--package=prqlc-ast --package=prqlc-parser --package=prql-compiler --package=prqlc'
29+
prqlc-test-fast:
30+
cargo clippy --all-targets {{packages}} -- -D warnings
3231

33-
cargo clippy --all-targets --target={{ target }} -- -D warnings
32+
# cargo insta test, but allowing multiple --package arguments
33+
INSTA_FORCE_PASS=1 cargo test --locked {{packages}}
3434

35-
@# Note that `--all-targets` doesn't refer to targets like
36-
@# `wasm32-unknown-unknown`; it refers to lib / bin / tests etc.
37-
@#
38-
@# Autoformatting does not make this clear to read, but this tertiary
39-
@# expression states to run:
40-
@# - External DB integration tests — `--features=test-dbs-external`
41-
@# on Linux
42-
@# - No features on Windows
43-
@# - Internal DB integration tests — `--features=test-dbs` otherwise
44-
@#
45-
@# Below, we also add:
46-
@# - Unreferenced snapshots - `--unreferenced=auto` on Linux
47-
@#
48-
@# We'd like to reenable on Windows, ref https://github.com/wangfenjin/duckdb-rs/issues/179.
35+
cargo insta review
4936

50-
cargo test --no-run --locked --target={{ target }}
37+
prqlc-test:
38+
cargo clippy --all-targets {{packages}} -- -D warnings
5139

52-
cargo insta test --target={{ target }}
40+
INSTA_FORCE_PASS=1 cargo test --locked
5341

5442
prqlc-python-build mode='debug':
5543
#!/usr/bin/env bash

prqlc/prql-compiler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ tokio-util = {version = "0.7", optional = true, features = ["compat"]}
5959
cfg-if = "1.0"
6060
insta = {version = "1.34", features = ["colors", "glob", "yaml"]}
6161
similar-asserts = "1.5.0"
62+
similar = {version = "2.3.0"}
6263

6364
[target.'cfg(not(target_family="wasm"))'.dev-dependencies]
6465
criterion = {version = "0.5.1"}

prqlc/prql-compiler/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,31 @@ impl<S: ToString> From<S> for SourceTree {
378378
mod tests {
379379
use crate::Target;
380380
use insta::assert_debug_snapshot;
381+
use prqlc_ast::expr::Ident;
381382
use std::str::FromStr;
382383

383384
pub fn compile(prql: &str) -> Result<String, super::ErrorMessages> {
384385
anstream::ColorChoice::Never.write_global();
385386
super::compile(prql, &super::Options::default().no_signature())
386387
}
387388

389+
#[test]
390+
fn test_starts_with() {
391+
// Over-testing, from co-pilot, can remove some of them.
392+
let a = Ident::from_path(vec!["a", "b", "c"]);
393+
let b = Ident::from_path(vec!["a", "b"]);
394+
let c = Ident::from_path(vec!["a", "b", "c", "d"]);
395+
let d = Ident::from_path(vec!["a", "b", "d"]);
396+
let e = Ident::from_path(vec!["a", "c"]);
397+
let f = Ident::from_path(vec!["b", "c"]);
398+
assert!(a.starts_with(&b));
399+
assert!(a.starts_with(&a));
400+
assert!(!a.starts_with(&c));
401+
assert!(!a.starts_with(&d));
402+
assert!(!a.starts_with(&e));
403+
assert!(!a.starts_with(&f));
404+
}
405+
388406
#[test]
389407
fn test_target_from_str() {
390408
assert_debug_snapshot!(Target::from_str("sql.postgres"), @r###"

prqlc/prql-compiler/tests/sql/test_error_messages.rs renamed to prqlc/prql-compiler/tests/sql/error_messages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! See also [test_bad_error_messages.rs](test_bad_error_messages.rs) for error
44
//! messages which need to be improved.
55
6-
use super::compile;
6+
use super::sql::compile;
77
use insta::assert_display_snapshot;
88

99
#[test]
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
mod test;
2-
mod test_bad_error_messages;
3-
mod test_error_messages;
1+
mod ast_code_matches;
2+
mod bad_error_messages;
3+
mod error_messages;
4+
mod parser;
5+
mod sql;
46

5-
use test::compile;
7+
use sql::compile;

prqlc/prqlc-parser/src/test.rs renamed to prqlc/prql-compiler/tests/sql/parser.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
#![cfg(test)]
2-
3-
use super::*;
41
use insta::{assert_debug_snapshot, assert_yaml_snapshot};
5-
use prqlc_ast::expr::{Expr, FuncCall};
2+
use itertools::Itertools;
3+
use prqlc_ast::error::*;
4+
use prqlc_ast::expr::*;
5+
use prqlc_ast::stmt::*;
66

77
/// Helper that does not track source_ids
88
fn parse_single(source: &str) -> Result<Vec<Stmt>, Vec<Error>> {
9-
parse_source(source, 0)
9+
prqlc_parser::parse_source(source, 0)
1010
}
1111

1212
fn parse_expr(source: &str) -> Result<Expr, Vec<Error>> {
13-
let tokens = Parser::parse(&lexer::lexer(), source).map_err(|errs| {
14-
errs.into_iter()
15-
.map(|e| convert_lexer_error(source, e, 0))
16-
.collect::<Vec<_>>()
17-
})?;
18-
19-
let stream = prepare_stream(tokens, source, 0);
20-
Parser::parse(&expr::expr_call().then_ignore(end()), stream)
21-
.map_err(|errs| errs.into_iter().map(construct_parser_error).collect())
13+
let source = format!("let result = ({source}\n)");
14+
15+
let stmts = parse_single(&source)?;
16+
let stmt = stmts.into_iter().exactly_one().unwrap();
17+
Ok(*stmt.kind.into_var_def().unwrap().value)
2218
}
2319

2420
#[test]

0 commit comments

Comments
 (0)