Skip to content

test(docs): add tests for examples in website hero and repo README #2710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 4, 2023

Conversation

eitsupi
Copy link
Member

@eitsupi eitsupi commented Jun 3, 2023

This PR renames the website tests to docs tests and adds more tests for examples in docs.

@eitsupi eitsupi changed the title test(docs): add tests for website hero and repo README test(docs): add tests for examples in website hero and repo README Jun 3, 2023
@eitsupi eitsupi marked this pull request as ready for review June 3, 2023 15:06
@eitsupi
Copy link
Member Author

eitsupi commented Jun 3, 2023

Wow, it seems the new test to have suddenly discovered an error in the README example!

$ cargo run -p prqlc compile
   Compiling prql-compiler v0.8.1 (/workspaces/prql/prql-compiler)
   Compiling prqlc v0.8.1 (/workspaces/prql/prql-compiler/prqlc)
    Finished dev [unoptimized + debuginfo] target(s) in 41.87s
     Running `target/debug/prqlc compile`
Enter PRQL, then press ctrl-d to compile:

from employees
filter country == "USA"                       # Each line transforms the previous result
aggregate {                                   # `aggregate` reduces each column to a value
  max salary,
  min salary,
  count,                                      # Trailing commas are allowed
}
Error:
   ╭─[Root.prql:6:3]
   │
 6 │   count,                                      # Trailing commas are allowed
   │   ──┬──
   │     ╰──── function std.aggregate, param `columns` expected type `scalar`, but found type `array -> int`
   │
   │ Help: Have you forgotten an argument to function std.count?
   │
   │ Note: Type `scalar` expands to `int || float || bool || text || date || time || timestamp || null`
───╯

@aljazerzen Any thoughts?

@aljazerzen
Copy link
Member

Yeah, I changed count to require the non_null argument. I don't like it and it breaks a lot of queries, so I intend to revert that before release.

@eitsupi
Copy link
Member Author

eitsupi commented Jun 3, 2023

It seems that the default argument used to be set to *.
Is there any reason why this cannot be restored? (Just curious)

let count = non_null:s"*" -> <scalar || column> s"COUNT({non_null})"

@aljazerzen
Copy link
Member

I needed it like that because I was changing how types work, and when a function is deemed a window function. It's an implementation thing.

Comment on lines +54 to +55
let re = Regex::new(r"(?s)```(elm|prql)\n(?P<prql>.+?)\n```").unwrap();
assert_ne!(re.find_iter(&contents).count(), 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever regex-ing!

In a way this is similar to

fn collect_book_examples() -> Result<Vec<Example>> {
, but easier to have this separate given they're in different places

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment with a ref

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was initially thinking of code block analysis using pulldown-cmark, but changed because it seemed like overkill. (And extracting code blocks with pulldown-cmark was too difficult for me!)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I def think writing another parser wouldn't be great!

This code is a very good balance IMO

@@ -0,0 +1,75 @@
use prql_compiler::Options;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW Rust unfortunately has poor performance with making lots of test binaries. So it would be faster if we could have this as a file within this test https://github.com/PRQL/prql/blob/65706a115a84997c608eaeda38b1aef1240fcec3/web/book/tests/snapshot.rs (which would change to a module, like this file is)

See the link at

We follow the advice in
<https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html>.

(but we can merge this and make the change / I'll make the change, I don't want to slow you down!)

@eitsupi eitsupi enabled auto-merge (squash) June 3, 2023 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants