Skip to content

Commit a1d0241

Browse files
authored
Fix compile warnings from tests (#257)
* Remove deprecated warnings from tests * Remove unused variables from tests
1 parent 5c5d3c1 commit a1d0241

25 files changed

Lines changed: 59 additions & 102 deletions

test-utils/src/sandbox.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ $(
104104

105105
#[test]
106106
fn $name() -> Result<(), Box<dyn std::error::Error>> {
107+
use assert_cmd::cargo::cargo_bin_cmd;
107108
let ts_content = $ts_content;
108109
let test_config: TestConfig = $test_config;
109110
println!("checking test config {:?}", test_config);
@@ -127,7 +128,7 @@ $(
127128
let file_result = fs::read_to_string(&file_path)?;
128129

129130
// EXECUTE
130-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
131+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
131132

132133
cmd.arg(parent_path.to_str().unwrap())
133134
.arg(format!("--ext={file_extension}"))
@@ -196,4 +197,4 @@ $(
196197
}
197198

198199
// MACRO ENDS
199-
)*};}
200+
)*};}

tests/alias.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#[cfg(test)]
22
mod alias {
3-
use assert_cmd::prelude::*;
4-
3+
use assert_cmd::cargo::cargo_bin_cmd;
54
use std::fs;
65
use std::io::Write;
7-
use std::process::Command;
86
use tempfile::tempdir;
97

108
#[test]
@@ -24,7 +22,7 @@ JOIN inventory ON items.inventory_id = inventory.id
2422
writeln!(temp_file, "{ts_content}")?;
2523

2624
// EXECUTE
27-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
25+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
2826
cmd
2927
.arg(parent_path.to_str().unwrap())
3028
.arg("--ext=ts")
@@ -60,7 +58,7 @@ JOIN inventory ON items.inventory_id = inventory.id
6058
writeln!(temp_file, "{ts_content}").unwrap();
6159

6260
// EXECUTE
63-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
61+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
6462
cmd
6563
.arg(parent_path.to_str().unwrap())
6664
.arg("--ext=ts")
@@ -95,7 +93,7 @@ JOIN inventory ON items.inventory_id = inventory.id
9593
writeln!(temp_file, "{ts_content}")?;
9694

9795
// EXECUTE
98-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
96+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
9997
cmd
10098
.arg(parent_path.to_str().unwrap())
10199
.arg("--ext=ts")

tests/cli.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(test)]
22
mod cli_test {
3-
use assert_cmd::Command;
3+
use assert_cmd::cargo::cargo_bin_cmd;
44
use std::env::current_dir;
55
use std::fs;
66
use std::io::Write;
@@ -23,7 +23,7 @@ mod cli_test {
2323
writeln!(temp_file, "{config_content}")?;
2424

2525
// EXECUTE
26-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
26+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
2727
cmd
2828
.arg(demo_path.to_str().unwrap())
2929
.arg("--ext=ts")
@@ -61,7 +61,7 @@ mod cli_test {
6161
writeln!(temp_file, "{config_content}")?;
6262

6363
// EXECUTE
64-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
64+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
6565
cmd
6666
.arg(demo_path.to_str().unwrap())
6767
.arg("--ext=ts")
@@ -114,7 +114,7 @@ mod cli_test {
114114
writeln!(temp_file, "{config_content}")?;
115115

116116
// EXECUTE
117-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
117+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
118118
cmd
119119
.arg(demo_path.to_str().unwrap())
120120
.arg("--ext=ts")
@@ -160,7 +160,7 @@ mod cli_test {
160160
writeln!(temp_file, "{config_content}")?;
161161

162162
// EXECUTE
163-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
163+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
164164
cmd
165165
.arg(demo_path.to_str().unwrap())
166166
.arg("--ext=ts")
@@ -209,7 +209,7 @@ mod cli_test {
209209
writeln!(temp_file, "{config_content}")?;
210210

211211
// EXECUTE
212-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
212+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
213213
cmd
214214
.arg(demo_path.to_str().unwrap())
215215
.arg("--ext=ts")
@@ -232,7 +232,6 @@ mod cli_test {
232232
let demo_dir = tempdir()?;
233233
let demo_path = demo_dir.path();
234234
let sql_file_path = demo_path.join("test-query.sql");
235-
let sample_query_path = demo_path.join("test-query.queries.ts");
236235

237236
let config_dir = tempdir()?;
238237
let config_file_path = config_dir.path().join(".sqlxrc.json");
@@ -262,7 +261,7 @@ mod cli_test {
262261
writeln!(config_file, "{config_content}")?;
263262

264263
// EXECUTE
265-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
264+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
266265
cmd
267266
.arg(demo_path.to_str().unwrap())
268267
.arg("--ext=ts")
@@ -282,7 +281,6 @@ mod cli_test {
282281
let demo_dir = tempdir()?;
283282
let demo_path = demo_dir.path();
284283
let sql_file_path = demo_path.join("test-query.sql");
285-
let sample_query_path = demo_path.join("test-query.queries.ts");
286284

287285
let config_dir = tempdir()?;
288286
let config_file_path = config_dir.path().join(".sqlxrc.json");
@@ -308,7 +306,7 @@ mod cli_test {
308306
writeln!(config_file, "{config_content}")?;
309307

310308
// EXECUTE
311-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
309+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
312310
cmd
313311
.arg(demo_path.to_str().unwrap())
314312
.arg("--ext=ts")
@@ -326,7 +324,6 @@ mod cli_test {
326324
let demo_dir = tempdir()?;
327325
let demo_path = demo_dir.path();
328326
let sql_file_path = demo_path.join("test-query.sql");
329-
let sample_query_path = demo_path.join("test-query.queries.ts");
330327

331328
let config_dir = tempdir()?;
332329
let config_file_path = config_dir.path().join(".sqlxrc.json");
@@ -356,7 +353,7 @@ mod cli_test {
356353
writeln!(config_file, "{config_content}")?;
357354

358355
// EXECUTE
359-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
356+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
360357
cmd
361358
.arg(demo_path.to_str().unwrap())
362359
.arg("--ext=ts")
@@ -376,7 +373,6 @@ mod cli_test {
376373
let demo_dir = tempdir()?;
377374
let demo_path = demo_dir.path();
378375
let sql_file_path = demo_path.join("test-query.sql");
379-
let sample_query_path = demo_path.join("test-query.queries.ts");
380376

381377
let config_dir = tempdir()?;
382378
let config_file_path = config_dir.path().join(".sqlxrc.json");
@@ -402,7 +398,7 @@ mod cli_test {
402398
writeln!(config_file, "{config_content}")?;
403399

404400
// EXECUTE
405-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
401+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
406402
cmd
407403
.arg(demo_path.to_str().unwrap())
408404
.arg("--ext=ts")
@@ -449,7 +445,7 @@ mod cli_test {
449445
writeln!(config_file, "{config_content}")?;
450446

451447
// EXECUTE - Pass in wrong db-url that should fail
452-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
448+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
453449
cmd
454450
.arg(demo_path.to_str().unwrap())
455451
.arg("--ext=ts")
@@ -498,7 +494,7 @@ mod cli_test {
498494
writeln!(config_file, "{config_content}")?;
499495

500496
// EXECUTE - Pass in wrong db-url that should fail
501-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
497+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
502498
cmd
503499
.arg(demo_path.to_str().unwrap())
504500
.arg("--ext=ts")

tests/column_naming_convention.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
///
33
#[cfg(test)]
44
mod column_naming_convention_tests {
5-
use assert_cmd::prelude::*;
6-
use predicates::prelude::*;
75
use std::env;
86
use std::fs;
97
use std::io::Write;
10-
use std::process::Command;
118
use tempfile::tempdir;
129

1310
use pretty_assertions::assert_eq;

tests/covert_to_camelcase.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
///
33
#[cfg(test)]
44
mod convert_camelcase_tests {
5-
use assert_cmd::prelude::*;
6-
use predicates::prelude::*;
75
use std::env;
86
use std::fs;
97
use std::io::Write;
10-
use std::process::Command;
118
use tempfile::tempdir;
129

1310
use pretty_assertions::assert_eq;

tests/demo_happy_path.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#[cfg(test)]
22
mod demo_happy_path_tests {
3-
use assert_cmd::prelude::*;
3+
use assert_cmd::cargo::cargo_bin_cmd;
44
use pretty_assertions::assert_eq;
55
use std::env::current_dir;
66
use std::fs;
77
use std::io::Write;
8-
use std::process::Command;
98
use walkdir::WalkDir;
109

1110
#[test]
@@ -15,7 +14,7 @@ mod demo_happy_path_tests {
1514
let demo_path = root_path.join("tests/demo");
1615

1716
// EXECUTE - Generate types for .ts files
18-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
17+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
1918
cmd
2019
.arg(demo_path.to_str().unwrap())
2120
.arg("--ext=ts")
@@ -32,7 +31,7 @@ mod demo_happy_path_tests {
3231
let file_extensions_path = demo_path.join("file_extensions");
3332
if file_extensions_path.exists() {
3433
for ext in &["js", "mts", "cts", "mjs", "cjs"] {
35-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
34+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
3635
cmd
3736
.arg(file_extensions_path.to_str().unwrap())
3837
.arg(format!("--ext={}", ext))
@@ -48,7 +47,7 @@ mod demo_happy_path_tests {
4847
// Also generate types for SQL files
4948
let sql_files_path = demo_path.join("sql_files");
5049
if sql_files_path.exists() {
51-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
50+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
5251
cmd
5352
.arg(sql_files_path.to_str().unwrap())
5453
.arg("--ext=sql")
@@ -98,7 +97,7 @@ mod demo_happy_path_tests {
9897
let demo_path = root_path.join("tests/demo/file_extensions");
9998

10099
// EXECUTE
101-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
100+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
102101
cmd
103102
.arg(demo_path.to_str().unwrap())
104103
.arg("--ext=js")
@@ -122,7 +121,7 @@ mod demo_happy_path_tests {
122121
let demo_path = root_path.join("tests/demo/file_extensions");
123122

124123
// EXECUTE
125-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
124+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
126125
cmd
127126
.arg(demo_path.to_str().unwrap())
128127
.arg("--ext=mts")
@@ -146,7 +145,7 @@ mod demo_happy_path_tests {
146145
let demo_path = root_path.join("tests/demo/file_extensions");
147146

148147
// EXECUTE
149-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
148+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
150149
cmd
151150
.arg(demo_path.to_str().unwrap())
152151
.arg("--ext=cts")
@@ -170,7 +169,7 @@ mod demo_happy_path_tests {
170169
let demo_path = root_path.join("tests/demo/file_extensions");
171170

172171
// EXECUTE
173-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
172+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
174173
cmd
175174
.arg(demo_path.to_str().unwrap())
176175
.arg("--ext=mjs")
@@ -194,7 +193,7 @@ mod demo_happy_path_tests {
194193
let demo_path = root_path.join("tests/demo/file_extensions");
195194

196195
// EXECUTE
197-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
196+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
198197
cmd
199198
.arg(demo_path.to_str().unwrap())
200199
.arg("--ext=cjs")
@@ -218,7 +217,7 @@ mod demo_happy_path_tests {
218217
let demo_path = root_path.join("tests/demo/sql_files");
219218

220219
// EXECUTE
221-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
220+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
222221
cmd
223222
.arg(demo_path.to_str().unwrap())
224223
.arg("--ext=sql")
@@ -242,7 +241,7 @@ mod demo_happy_path_tests {
242241
let demo_path = root_path.join("tests/demo/file_extensions");
243242

244243
// EXECUTE - Test scanning multiple extensions at once
245-
let mut cmd = Command::cargo_bin("sqlx-ts").unwrap();
244+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
246245
cmd
247246
.arg(demo_path.to_str().unwrap())
248247
.arg("--ext=js")

tests/dotenv.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(test)]
22
mod dotenv_test {
3-
use assert_cmd::Command;
3+
use assert_cmd::cargo::cargo_bin_cmd;
44
use std::fs::{self};
55

66
use tempfile::tempdir;
@@ -24,7 +24,7 @@ DB_NAME=postgres
2424
fs::create_dir_all(&sample_dir)?;
2525
fs::copy("tests/sample/sample.ts", sample_dir.join("sample.ts"))?;
2626

27-
let mut cmd = Command::cargo_bin("sqlx-ts")?;
27+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
2828
cmd
2929
.current_dir(temp_dir.path())
3030
.arg("--ext=ts")
@@ -58,7 +58,7 @@ DB_NAME=postgres
5858
fs::create_dir_all(&sample_dir)?;
5959
fs::copy("tests/sample/sample.ts", sample_dir.join("sample.ts"))?;
6060

61-
let mut cmd = Command::cargo_bin("sqlx-ts")?;
61+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
6262
cmd
6363
.current_dir(temp_dir.path())
6464
.arg("--ext=ts")
@@ -80,7 +80,7 @@ DB_NAME=postgres
8080
fs::create_dir_all(&sample_dir)?;
8181
fs::copy("tests/sample/sample.ts", sample_dir.join("sample.ts"))?;
8282

83-
let mut cmd = Command::cargo_bin("sqlx-ts")?;
83+
let mut cmd = cargo_bin_cmd!("sqlx-ts");
8484
cmd
8585
.current_dir(temp_dir.path())
8686
.arg("--ext=ts")

tests/enums.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#[cfg(test)]
22
mod enums {
3-
use assert_cmd::prelude::*;
43
use pretty_assertions::assert_eq;
54
use std::env;
65
use std::fs;
76
use std::io::Write;
8-
use std::process::Command;
97
use tempfile::tempdir;
108

119
use test_utils::test_utils::TSString;

0 commit comments

Comments
 (0)