1
+ use anyhow:: Context ;
1
2
use assert_cmd:: Command ;
2
3
use std:: cmp:: Ordering ;
3
4
use std:: fs:: read_dir;
@@ -94,9 +95,18 @@ impl AddMigrations {
94
95
} )
95
96
}
96
97
97
- fn with_config ( mut self , path : & str ) -> Self {
98
+ fn with_config ( mut self , filename : & str ) -> anyhow:: Result < Self > {
99
+ let path = format ! ( "sqlx-cli/tests/assets/{filename}" ) ;
100
+
101
+ let path = std:: fs:: canonicalize ( & path)
102
+ . with_context ( || format ! ( "error canonicalizing path {path:?}" ) ) ?;
103
+
104
+ let path = path
105
+ . to_str ( )
106
+ . with_context ( || format ! ( "canonicalized version of path {path:?} is not UTF-8" ) ) ?;
107
+
98
108
self . config_arg = Some ( format ! ( "--config={path}" ) ) ;
99
- self
109
+ Ok ( self )
100
110
}
101
111
102
112
fn run (
@@ -311,7 +321,7 @@ fn add_migration_timestamp_reversible() -> anyhow::Result<()> {
311
321
#[ test]
312
322
fn add_migration_config_default_type_reversible ( ) -> anyhow:: Result < ( ) > {
313
323
let files = AddMigrations :: new ( ) ?
314
- . with_config ( "sqlx-cli/tests/assets/ config_default_type_reversible.toml" )
324
+ . with_config ( "config_default_type_reversible.toml" ) ?
315
325
// Type should default to reversible without any flags
316
326
. run ( "hello world" , false , false , false , true ) ?
317
327
. run ( "hello world2" , false , false , false , true ) ?
@@ -331,7 +341,7 @@ fn add_migration_config_default_type_reversible() -> anyhow::Result<()> {
331
341
#[ test]
332
342
fn add_migration_config_default_versioning_sequential ( ) -> anyhow:: Result < ( ) > {
333
343
let files = AddMigrations :: new ( ) ?
334
- . with_config ( "sqlx-cli/tests/assets/ config_default_versioning_sequential.toml" )
344
+ . with_config ( "config_default_versioning_sequential.toml" ) ?
335
345
// Versioning should default to timestamp without any flags
336
346
. run ( "hello world" , false , false , false , true ) ?
337
347
. run ( "hello world2" , false , false , false , true ) ?
@@ -368,8 +378,7 @@ fn add_migration_config_default_versioning_timestamp() -> anyhow::Result<()> {
368
378
assert_eq ! ( files[ 2 ] . id, 3 ) ;
369
379
370
380
// Now set a config that uses `default-versioning = "timestamp"`
371
- let migrations =
372
- migrations. with_config ( "sqlx-cli/tests/assets/config_default_versioning_timestamp.toml" ) ;
381
+ let migrations = migrations. with_config ( "config_default_versioning_timestamp.toml" ) ?;
373
382
374
383
// Now the default should be a timestamp
375
384
migrations
0 commit comments