Skip to content

Commit ed4db52

Browse files
committed
progress
1 parent 924aeba commit ed4db52

14 files changed

+252
-35
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ squawk/
3131
crates/pgt_treesitter_grammar/src/grammar.json
3232
crates/pgt_treesitter_grammar/src/node-types.json
3333
crates/pgt_treesitter_grammar/src/parser.c
34+
crates/pgt_treesitter_grammar/src/parser.c.codex-session-id
35+
.codex-session-id

crates/pgt_cli/tests/assert_cmd.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,48 @@ use std::path::PathBuf;
22

33
use assert_cmd::Command;
44
use insta::assert_snapshot;
5+
use std::process::ExitStatus;
56

67
const BIN: &str = "postgres-language-server";
8+
const CONFIG_PATH: &str = "tests/fixtures/postgres-language-server.jsonc";
79

810
#[test]
11+
#[cfg_attr(
12+
not(target_os = "linux"),
13+
ignore = "snapshot expectations only validated on Linux"
14+
)]
915
fn test_cli_check_command() {
1016
let output = Command::cargo_bin(BIN)
1117
.unwrap()
1218
.args([
1319
"check",
20+
"--config-path",
21+
CONFIG_PATH,
1422
PathBuf::from("tests/fixtures/test.sql").to_str().unwrap(),
1523
])
1624
.output()
1725
.unwrap();
1826

1927
assert!(!output.status.success(), "command unexpectedly succeeded");
2028

21-
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
22-
assert_snapshot!(normalize_durations(&stdout));
29+
let stdout = String::from_utf8_lossy(&output.stdout);
30+
let stderr = String::from_utf8_lossy(&output.stderr);
31+
assert_snapshot!(normalize_output(output.status, &stdout, &stderr));
32+
}
33+
34+
fn normalize_output(status: ExitStatus, stdout: &str, stderr: &str) -> String {
35+
let normalized_stdout = normalize_durations(stdout);
36+
let normalized_stderr = normalize_durations(stderr);
37+
let status_label = if status.success() {
38+
"success"
39+
} else {
40+
"failure"
41+
};
42+
format!(
43+
"status: {status_label}\nstdout:\n{}\nstderr:\n{}\n",
44+
normalized_stdout.trim_end(),
45+
normalized_stderr.trim_end()
46+
)
2347
}
2448

2549
fn normalize_durations(input: &str) -> String {

crates/pgt_cli/tests/commands/check.rs

Lines changed: 103 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
use assert_cmd::Command;
22
use insta::assert_snapshot;
3-
use std::path::PathBuf;
3+
use std::path::Path;
4+
use std::process::ExitStatus;
45

56
const BIN: &str = "postgres-language-server";
7+
const CONFIG_PATH: &str = "tests/fixtures/postgres-language-server.jsonc";
68

79
fn run_check(args: &[&str]) -> String {
10+
let mut full_args = vec!["check", "--config-path", CONFIG_PATH];
11+
full_args.extend_from_slice(args);
12+
run_check_with(&full_args, None, None)
13+
}
14+
15+
fn run_check_with(args: &[&str], stdin: Option<&str>, cwd: Option<&Path>) -> String {
816
let mut cmd = Command::cargo_bin(BIN).expect("binary not built");
9-
let mut full_args = vec!["check".to_string()];
10-
full_args.extend(args.iter().map(|s| s.to_string()));
11-
let test_sql = PathBuf::from("tests/fixtures/test.sql");
12-
full_args.push(test_sql.to_str().unwrap().to_string());
13-
14-
let output = cmd.args(&full_args).output().expect("failed to run CLI");
15-
assert!(
16-
!output.status.success(),
17-
"command unexpectedly succeeded: {:?}",
18-
output.status
19-
);
20-
21-
normalize_durations(&String::from_utf8_lossy(&output.stdout))
17+
if let Some(dir) = cwd {
18+
cmd.current_dir(dir);
19+
}
20+
if let Some(input) = stdin {
21+
cmd.write_stdin(input);
22+
}
23+
24+
let output = cmd.args(args).output().expect("failed to run CLI");
25+
26+
normalize_output(
27+
output.status,
28+
&String::from_utf8_lossy(&output.stdout),
29+
&String::from_utf8_lossy(&output.stderr),
30+
)
2231
}
2332

2433
fn normalize_durations(input: &str) -> String {
@@ -57,22 +66,98 @@ fn normalize_durations(input: &str) -> String {
5766
content
5867
}
5968

69+
fn normalize_output(status: ExitStatus, stdout: &str, stderr: &str) -> String {
70+
let normalized_stdout = normalize_durations(stdout);
71+
let normalized_stderr = normalize_durations(stderr);
72+
let status_label = if status.success() {
73+
"success"
74+
} else {
75+
"failure"
76+
};
77+
format!(
78+
"status: {status_label}\nstdout:\n{}\nstderr:\n{}\n",
79+
normalized_stdout.trim_end(),
80+
normalized_stderr.trim_end()
81+
)
82+
}
83+
6084
#[test]
85+
#[cfg_attr(
86+
not(target_os = "linux"),
87+
ignore = "snapshot expectations only validated on Linux"
88+
)]
6189
fn check_default_reporter_snapshot() {
62-
assert_snapshot!(run_check(&[]));
90+
assert_snapshot!(run_check(&["tests/fixtures/test.sql"]));
6391
}
6492

6593
#[test]
94+
#[cfg_attr(
95+
not(target_os = "linux"),
96+
ignore = "snapshot expectations only validated on Linux"
97+
)]
6698
fn check_github_reporter_snapshot() {
67-
assert_snapshot!(run_check(&["--reporter", "github"]));
99+
assert_snapshot!(run_check(&[
100+
"--reporter",
101+
"github",
102+
"tests/fixtures/test.sql"
103+
]));
68104
}
69105

70106
#[test]
107+
#[cfg_attr(
108+
not(target_os = "linux"),
109+
ignore = "snapshot expectations only validated on Linux"
110+
)]
71111
fn check_gitlab_reporter_snapshot() {
72-
assert_snapshot!(run_check(&["--reporter", "gitlab"]));
112+
assert_snapshot!(run_check(&[
113+
"--reporter",
114+
"gitlab",
115+
"tests/fixtures/test.sql"
116+
]));
73117
}
74118

75119
#[test]
120+
#[cfg_attr(
121+
not(target_os = "linux"),
122+
ignore = "snapshot expectations only validated on Linux"
123+
)]
76124
fn check_junit_reporter_snapshot() {
77-
assert_snapshot!(run_check(&["--reporter", "junit"]));
125+
assert_snapshot!(run_check(&[
126+
"--reporter",
127+
"junit",
128+
"tests/fixtures/test.sql"
129+
]));
130+
}
131+
132+
#[test]
133+
#[cfg_attr(
134+
not(target_os = "linux"),
135+
ignore = "snapshot expectations only validated on Linux"
136+
)]
137+
fn check_stdin_snapshot() {
138+
assert_snapshot!(run_check_with(
139+
&[
140+
"check",
141+
"--config-path",
142+
CONFIG_PATH,
143+
"--stdin-file-path",
144+
"virtual.sql"
145+
],
146+
Some("alter tqjable stdin drop column id;\n"),
147+
None
148+
));
149+
}
150+
151+
#[test]
152+
#[cfg_attr(
153+
not(target_os = "linux"),
154+
ignore = "snapshot expectations only validated on Linux"
155+
)]
156+
fn check_directory_traversal_snapshot() {
157+
let project_dir = Path::new("tests/fixtures/traversal");
158+
assert_snapshot!(run_check_with(
159+
&["check", "--diagnostic-level", "info", "."],
160+
None,
161+
Some(project_dir)
162+
));
78163
}
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
---
22
source: crates/pgt_cli/tests/commands/check.rs
3-
expression: "run_check(&[])"
3+
expression: "run_check(&[\"tests/fixtures/test.sql\"])"
44
snapshot_kind: text
55
---
6-
Warning: You are using the deprecated config filename 'postgrestools.jsonc'. Please rename it to 'postgres-language-server.jsonc'. Support for the old filename will be removed in a future version.
7-
6+
status: failure
7+
stdout:
88
Checked 1 file in <duration>. No fixes applied.
99
Found 1 error.
10+
stderr:
11+
tests/fixtures/test.sql:1:1 syntax ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
12+
13+
× Invalid statement: syntax error at or near "tqjable"
14+
15+
> 1 │ alter tqjable test drop column id;
16+
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
2 │
18+
19+
20+
check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
21+
22+
× Some errors were emitted while running checks.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
source: crates/pgt_cli/tests/commands/check.rs
3+
expression: "run_check_with(&[\"check\", \"--diagnostic-level\", \"info\", \".\"], None,\nSome(project_dir))"
4+
snapshot_kind: text
5+
---
6+
status: failure
7+
stdout:
8+
Checked 2 files in <duration>. No fixes applied.
9+
Found 2 errors.
10+
stderr:
11+
./bad.sql:1:1 syntax ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
12+
13+
× Invalid statement: syntax error at or near "tqjable"
14+
15+
> 1 │ alter tqjable bad drop column id;
16+
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
2 │
18+
19+
20+
./another_bad.sql:1:1 syntax ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
21+
22+
× Invalid statement: syntax error at or near "tqjable"
23+
24+
> 1 │ alter tqjable another drop column id;
25+
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
2 │
27+
28+
29+
check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
30+
31+
× Some errors were emitted while running checks.
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
---
22
source: crates/pgt_cli/tests/commands/check.rs
3-
expression: "run_check(&[\"--reporter\", \"github\"])"
3+
expression: "run_check(&[\"--reporter\", \"github\", \"tests/fixtures/test.sql\"])"
44
snapshot_kind: text
55
---
6-
Warning: You are using the deprecated config filename 'postgrestools.jsonc'. Please rename it to 'postgres-language-server.jsonc'. Support for the old filename will be removed in a future version.
7-
6+
status: failure
7+
stdout:
88
::error title=syntax,file=tests/fixtures/test.sql,line=1,endLine=1,col=1,endColumn=35::Invalid statement: syntax error at or near "tqjable"
9+
stderr:
10+
check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
11+
12+
× Some errors were emitted while running checks.

crates/pgt_cli/tests/commands/snapshots/main__commands__check__check_gitlab_reporter_snapshot.snap

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
source: crates/pgt_cli/tests/commands/check.rs
3-
expression: "run_check(&[\"--reporter\", \"gitlab\"])"
3+
expression: "run_check(&[\"--reporter\", \"gitlab\", \"tests/fixtures/test.sql\"])"
44
snapshot_kind: text
55
---
6-
Warning: You are using the deprecated config filename 'postgrestools.jsonc'. Please rename it to 'postgres-language-server.jsonc'. Support for the old filename will be removed in a future version.
7-
6+
status: failure
7+
stdout:
88
[
99
{
1010
"description": "Invalid statement: syntax error at or near \"tqjable\"",
@@ -19,3 +19,7 @@ Warning: You are using the deprecated config filename 'postgrestools.jsonc'. Ple
1919
}
2020
}
2121
]
22+
stderr:
23+
check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
24+
25+
× Some errors were emitted while running checks.
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
source: crates/pgt_cli/tests/commands/check.rs
3-
expression: "run_check(&[\"--reporter\", \"junit\"])"
3+
expression: "run_check(&[\"--reporter\", \"junit\", \"tests/fixtures/test.sql\"])"
44
snapshot_kind: text
55
---
6-
Warning: You are using the deprecated config filename 'postgrestools.jsonc'. Please rename it to 'postgres-language-server.jsonc'. Support for the old filename will be removed in a future version.
7-
6+
status: failure
7+
stdout:
88
<?xml version="1.0" encoding="UTF-8"?>
99
<testsuites name="PostgresTools" tests="1" failures="1" errors="1" time="<duration>">
1010
<testsuite name="tests/fixtures/test.sql" tests="1" disabled="0" errors="0" failures="1" package="org.pgt">
@@ -13,3 +13,7 @@ Warning: You are using the deprecated config filename 'postgrestools.jsonc'. Ple
1313
</testcase>
1414
</testsuite>
1515
</testsuites>
16+
stderr:
17+
check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
18+
19+
× Some errors were emitted while running checks.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
source: crates/pgt_cli/tests/commands/check.rs
3+
expression: "run_check_with(&[\"check\", \"--config-path\", CONFIG_PATH, \"--stdin-file-path\",\n\"virtual.sql\"], Some(\"alter tqjable stdin drop column id;\\n\"), None)"
4+
snapshot_kind: text
5+
---
6+
status: success
7+
stdout:
8+
alter tqjable stdin drop column id;
9+
stderr:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://pg-language-server.com/schema/postgres-language-server.schema.json",
3+
"vcs": {
4+
"enabled": false,
5+
"clientKind": "git",
6+
"useIgnoreFile": false
7+
},
8+
"files": {
9+
"ignore": []
10+
},
11+
"linter": {
12+
"enabled": true,
13+
"rules": {
14+
"recommended": true
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)