playr 0.13.0

A minimal TUI music player that plays local files and contacts nothing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
//! Command-line behaviour, run against the built binary.
//!
//! No command here reaches playback: the files are not audio, and without a
//! terminal the interface refuses to start.

use std::path::Path;
use std::process::{Command, Stdio};

fn playr(db: &Path, args: &[&str]) {
    Command::new(env!("CARGO_BIN_EXE_playr"))
        // Not the config or the instance lock of whoever runs the tests.
        .env("XDG_CONFIG_HOME", db.parent().unwrap())
        .env("XDG_DATA_HOME", db.parent().unwrap())
        .arg("--db")
        .arg(db)
        .args(args)
        .stdin(Stdio::null())
        .stdout(Stdio::null())
        .stderr(Stdio::null())
        .status()
        .unwrap();
}

#[test]
fn only_scan_creates_the_library() {
    let dir = tempfile::tempdir().unwrap();
    let db = dir.path().join("playr/library.db");
    let file = dir.path().join("x.mp3");
    std::fs::write(&file, b"x").unwrap();

    for args in [
        vec![file.to_str().unwrap()],
        vec![],
        vec!["search", "anything"],
        vec!["playlist", "late"],
        vec!["playlists"],
    ] {
        playr(&db, &args);
        assert!(
            !db.exists(),
            "`playr {}` created the library",
            args.join(" ")
        );
    }

    playr(&db, &["scan", dir.path().to_str().unwrap()]);
    assert!(db.exists(), "`playr scan` did not create the library");
}

/// Runs playr on the library `db`, with no terminal and no user settings,
/// returning its exit code, stdout and stderr.
fn output(db: &Path, args: &[&str]) -> (Option<i32>, String, String) {
    let out = Command::new(env!("CARGO_BIN_EXE_playr"))
        .env("XDG_CONFIG_HOME", db.parent().unwrap())
        .env("XDG_DATA_HOME", db.parent().unwrap())
        .arg("--db")
        .arg(db)
        .args(args)
        .stdin(Stdio::null())
        .output()
        .unwrap();
    (
        out.status.code(),
        String::from_utf8_lossy(&out.stdout).into_owned(),
        String::from_utf8_lossy(&out.stderr).into_owned(),
    )
}

#[test]
fn bad_arguments_are_refused_before_anything_runs() {
    let dir = tempfile::tempdir().unwrap();
    let db = dir.path().join("library.db");
    for (args, error) in [
        (&["--bogus"][..], "unexpected argument '--bogus'"),
        (&["playlists", "--bogus"], "unexpected argument '--bogus'"),
        (&["formats", "extra"], "unexpected argument 'extra'"),
        (&["search", "rock", "--db"], "a value is required for '--db"),
        (&["search"], "<QUERY>"),
        (&["scan", "--bogus"], "unexpected argument '--bogus'"),
    ] {
        let (code, _, stderr) = output(&db, args);
        assert_eq!(code, Some(2), "playr {args:?}: {stderr}");
        assert!(stderr.contains(error), "playr {args:?}: {stderr}");
    }
    let (code, _, stderr) = output(&db, &["scan"]);
    assert_eq!(code, Some(1), "bare scan with no library: {stderr}");
    assert!(
        stderr.contains("no directories to scan"),
        "bare scan with no library: {stderr}"
    );
    let (code, _, stderr) = output(&db, &["prune"]);
    assert_eq!(code, Some(1), "bare prune with no library: {stderr}");
    assert!(
        stderr.contains("no library"),
        "bare prune with no library: {stderr}"
    );
    assert!(!db.exists());
}

#[test]
fn each_subcommand_has_its_own_help() {
    let dir = tempfile::tempdir().unwrap();
    let db = dir.path().join("library.db");
    // Windows names the program `playr.exe` in usage lines.
    for (command, text) in [
        ("scan", "scan [OPTIONS] [DIR]..."),
        ("prune", "prune [OPTIONS] [DIR]..."),
        ("search", "--json"),
    ] {
        let (code, stdout, _) = output(&db, &[command, "--help"]);
        assert_eq!(code, Some(0));
        assert!(stdout.contains(text), "playr {command} --help: {stdout}");
    }
    // Scanning `--help` would have created the library.
    assert!(!db.exists(), "playr scan --help scanned");
}

#[test]
fn search_json_prints_every_match_with_its_columns() {
    use playr_core::db::{self, Track};
    let dir = tempfile::tempdir().unwrap();
    let db_path = dir.path().join("library.db");
    let conn = db::open(&db_path).unwrap();
    for track in [
        Track {
            path: "/m/peace piece.flac".into(),
            title: Some("Peace Piece".into()),
            artist: Some("Bill Evans".into()),
            track_no: Some(3),
            duration_ms: Some(393_000),
            mtime: 1,
            size: 2,
            ..Default::default()
        },
        Track {
            path: "/m/evans-untagged.wav".into(),
            mtime: 1,
            size: 2,
            ..Default::default()
        },
        Track {
            path: "/m/other.flac".into(),
            title: Some("Other".into()),
            mtime: 1,
            size: 2,
            ..Default::default()
        },
    ] {
        db::upsert(&conn, &track).unwrap();
    }
    drop(conn);

    let (code, stdout, stderr) = output(&db_path, &["search", "--json", "evans"]);
    assert_eq!(code, Some(0), "{stderr}");
    let rows: serde_json::Value = serde_json::from_str(&stdout).unwrap();
    let rows = rows.as_array().unwrap();
    let paths: Vec<&str> = rows.iter().map(|r| r["path"].as_str().unwrap()).collect();
    assert_eq!(paths.len(), 2, "{stdout}");
    assert!(paths.contains(&"/m/evans-untagged.wav"), "{stdout}");
    let piece = rows
        .iter()
        .find(|r| r["path"] == "/m/peace piece.flac")
        .unwrap();
    assert_eq!(piece["title"], "Peace Piece");
    assert_eq!(piece["artist"], "Bill Evans");
    assert_eq!(piece["track_no"], 3);
    assert_eq!(piece["duration_ms"], 393_000);
    assert!(piece["album"].is_null(), "{piece}");
    assert!(piece["id"].as_i64().unwrap() > 0);
    assert_eq!(piece.as_object().unwrap().len(), 16, "{piece}");

    // No match still prints valid JSON, and fails as a plain search does.
    let (code, stdout, _) = output(&db_path, &["search", "--json", "coltrane"]);
    assert_eq!((code, stdout.trim()), (Some(1), "[]"));
    // After --, a query may look like an option.
    let (code, stdout, stderr) = output(&db_path, &["search", "--json", "--", "--db"]);
    assert_eq!((code, stdout.trim()), (Some(1), "[]"), "{stderr}");
}

/// Runs playr with a settings directory and no terminal, returning its exit status and stderr.
fn with_config(dir: &Path, args: &[&str]) -> (bool, String) {
    let out = Command::new(env!("CARGO_BIN_EXE_playr"))
        .env("XDG_CONFIG_HOME", dir)
        .env("XDG_DATA_HOME", dir)
        .arg("--db")
        .arg(dir.join("library.db"))
        .args(args)
        .stdin(Stdio::null())
        .output()
        .unwrap();
    (
        out.status.success(),
        String::from_utf8_lossy(&out.stderr).into_owned(),
    )
}

#[test]
fn bad_settings_stop_playr_before_it_starts_and_list_every_error() {
    let dir = tempfile::tempdir().unwrap();
    std::fs::create_dir(dir.path().join("playr")).unwrap();
    let default = dir.path().join("playr/settings.toml");
    std::fs::write(&default, "volume = 50\nfrob = 1\n[keys]\nd = 'remove'\n").unwrap();

    let (ok, stderr) = with_config(dir.path(), &[]);
    assert!(!ok);
    let path = default.display();
    assert!(
        stderr.contains(&format!("playr: {path}: line 2: unknown setting: frob")),
        "{stderr}"
    );
    assert!(
        stderr.contains(&format!("playr: {path}: line 4: :remove works")),
        "{stderr}"
    );
    // Stopped at the settings, not at the missing terminal.
    assert!(!stderr.contains("terminal"), "{stderr}");

    // --settings replaces the default file, and must exist.
    let other = dir.path().join("other.toml");
    std::fs::write(&other, "volume = 50\n").unwrap();
    let (_, stderr) = with_config(dir.path(), &["--settings", other.to_str().unwrap()]);
    assert!(
        !stderr.contains("line 2"),
        "the default file was read: {stderr}"
    );
    let (ok, stderr) = with_config(dir.path(), &["--settings", "/nonexistent/playr.toml"]);
    assert!(!ok);
    assert!(
        stderr.contains("playr: /nonexistent/playr.toml:"),
        "{stderr}"
    );
}

#[test]
fn a_command_that_does_not_play_warns_of_bad_settings_and_runs() {
    let dir = tempfile::tempdir().unwrap();
    std::fs::create_dir(dir.path().join("playr")).unwrap();
    let default = dir.path().join("playr/settings.toml");
    std::fs::write(&default, "frob = 1\n").unwrap();
    let warning = format!(
        "playr: warning: {}: line 1: unknown setting: frob",
        default.display()
    );

    // Not `devices`, which fails on a machine with no audio.
    for args in [&["formats"][..], &["playlists"]] {
        let (ok, stderr) = with_config(dir.path(), args);
        assert!(ok, "`playr {}`: {stderr}", args.join(" "));
        assert!(
            stderr.contains(&warning),
            "`playr {}`: {stderr}",
            args.join(" ")
        );
    }
    // A search that would play stops at the settings, before searching.
    let (ok, stderr) = with_config(dir.path(), &["search", "anything"]);
    assert!(!ok);
    assert!(!stderr.contains("warning"), "{stderr}");
    assert!(!stderr.contains("nothing matches"), "{stderr}");
}

#[test]
fn a_missing_home_variable_does_not_stop_playr() {
    // Windows does not set HOME; the defaults expand ~ and must still load.
    // A bad setting stops playr just after the defaults load and before it
    // takes the terminal, so the test does not depend on having one.
    let dir = tempfile::tempdir().unwrap();
    let settings = dir.path().join("settings.toml");
    std::fs::write(&settings, "frob = 1\n").unwrap();
    let out = Command::new(env!("CARGO_BIN_EXE_playr"))
        .env_remove("HOME")
        .env_remove("XDG_CONFIG_HOME")
        .env("XDG_DATA_HOME", dir.path())
        .arg("--db")
        .arg(dir.path().join("library.db"))
        .arg("--settings")
        .arg(&settings)
        .stdin(Stdio::null())
        .output()
        .unwrap();
    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(!stderr.contains("panicked"), "{stderr}");
    assert!(stderr.contains("line 1: unknown setting: frob"), "{stderr}");
}

#[test]
fn a_second_playr_is_refused_but_reading_the_library_is_not() {
    use playr_app::instance::{claim_at, ALREADY_RUNNING};
    let dir = tempfile::tempdir().unwrap();
    let data = dir.path().join("data");
    let db = dir.path().join("library.db");
    let songs = dir.path().join("music");
    std::fs::create_dir(&songs).unwrap();
    // Another playr, the terminal or the window, is running.
    let _running = claim_at(&data.join("playr/instance.lock")).unwrap();
    let run = |args: &[&str]| {
        Command::new(env!("CARGO_BIN_EXE_playr"))
            .env("XDG_DATA_HOME", &data)
            .env("XDG_CONFIG_HOME", dir.path())
            .arg("--db")
            .arg(&db)
            .args(args)
            .stdin(Stdio::null())
            .output()
            .unwrap()
    };

    for args in [vec!["scan", songs.to_str().unwrap()], vec![]] {
        let out = run(&args);
        let stderr = String::from_utf8_lossy(&out.stderr);
        assert!(!out.status.success(), "playr {args:?} ran");
        assert!(stderr.contains(ALREADY_RUNNING), "playr {args:?}: {stderr}");
    }
    assert!(!db.exists(), "a refused scan created the library");

    // Reading needs no lock.
    for args in [&["playlists"][..], &["formats"], &["search", "--json", "x"]] {
        let out = run(args);
        let stderr = String::from_utf8_lossy(&out.stderr);
        assert!(
            !stderr.contains(ALREADY_RUNNING),
            "playr {args:?}: {stderr}"
        );
    }
}

#[test]
fn scan_keeps_missing_tracks_and_prune_removes_them_with_their_marks() {
    use playr_core::db::{self, query, Track};
    let dir = tempfile::tempdir().unwrap();
    let music = dir.path().canonicalize().unwrap().join("music");
    std::fs::create_dir(&music).unwrap();
    let db_path = dir.path().join("library.db");
    let gone = music.join("gone.flac").to_string_lossy().into_owned();
    let conn = db::open(&db_path).unwrap();
    let track = Track {
        path: gone.clone(),
        mtime: 1,
        size: 1,
        ..Default::default()
    };
    db::upsert(&conn, &track).unwrap();
    query::add_mark(
        &conn,
        &gone,
        query::Mark {
            frame: 1,
            rate: 8000,
        },
    )
    .unwrap();
    drop(conn);

    let (code, stdout, stderr) = output(&db_path, &["scan", music.to_str().unwrap()]);
    assert_eq!(code, Some(0), "{stderr}");
    assert!(stdout.contains("1 tracks missing"), "{stdout}");
    let conn = db::open(&db_path).unwrap();
    assert_eq!(query::count(&conn).unwrap(), 1, "a scan removed a track");

    let (code, stdout, stderr) = output(&db_path, &["prune", music.to_str().unwrap()]);
    assert_eq!(code, Some(0), "{stderr}");
    assert!(stdout.contains("removed 1 tracks and 1 marks"), "{stdout}");
    assert_eq!(query::count(&conn).unwrap(), 0);
    assert!(query::marks(&conn, &gone).unwrap().is_empty());

    // Pruning needs a library; it does not make one.
    let other = dir.path().join("other.db");
    let (code, _, stderr) = output(&other, &["prune", music.to_str().unwrap()]);
    assert_eq!(code, Some(1), "{stderr}");
    assert!(stderr.contains("no library"), "{stderr}");
    assert!(!other.exists());
}

#[test]
fn roots_lists_what_was_scanned_and_rm_forgets_it() {
    let dir = tempfile::tempdir().unwrap();
    let db = dir.path().join("playr/library.db");
    let songs = dir.path().join("music");
    std::fs::create_dir(&songs).unwrap();
    std::fs::write(songs.join("a.wav"), b"not audio").unwrap();

    // No library yet: listing and forgetting have nothing to read.
    let (code, _, stderr) = output(&db, &["roots"]);
    assert_eq!(code, Some(1), "{stderr}");
    assert!(stderr.contains("no library"), "{stderr}");

    playr(&db, &["scan", songs.to_str().unwrap()]);
    let canonical = songs.canonicalize().unwrap();
    let (code, stdout, _) = output(&db, &["roots"]);
    assert_eq!(code, Some(0));
    assert_eq!(stdout.trim(), canonical.display().to_string());

    // A directory that is not a root is reported and fails.
    let (code, _, stderr) = output(&db, &["roots", "rm", dir.path().to_str().unwrap()]);
    assert_eq!(code, Some(1), "{stderr}");
    assert!(stderr.contains("not one of the library's"), "{stderr}");

    let (code, stdout, stderr) = output(&db, &["roots", "rm", songs.to_str().unwrap()]);
    assert_eq!(code, Some(0), "{stderr}");
    assert!(stdout.contains("forgot"), "{stdout}");
    let (_, stdout, _) = output(&db, &["roots"]);
    assert!(stdout.trim().is_empty(), "still listed: {stdout}");
}

/// Writes a second of a mono sine as a WAV of `bits` bits, the low `pad` of
/// them always zero.
fn sine_wav(path: &Path, bits: u16, pad: u32) {
    let spec = hound::WavSpec {
        channels: 1,
        sample_rate: 44100,
        bits_per_sample: bits,
        sample_format: hound::SampleFormat::Int,
    };
    let mut w = hound::WavWriter::create(path, spec).unwrap();
    let full = ((1i64 << (bits - 1)) - 1) as f64;
    for i in 0..44100 {
        let v = (i as f64 * 0.06).sin() * 0.25 * full;
        w.write_sample(((v as i64 >> pad) << pad) as i32).unwrap();
    }
    w.finalize().unwrap();
}

#[test]
fn analyze_records_findings_and_skips_what_is_current() {
    let dir = tempfile::tempdir().unwrap();
    let music = dir.path().join("music");
    std::fs::create_dir(&music).unwrap();
    sine_wav(&music.join("plain.wav"), 16, 0);
    sine_wav(&music.join("padded.wav"), 24, 8);
    let db = dir.path().join("library.db");

    let (code, _, stderr) = output(&db, &["analyze"]);
    assert_eq!(code, Some(1), "{stderr}");
    assert!(stderr.contains("no library"), "{stderr}");

    playr(&db, &["scan", music.to_str().unwrap()]);
    // A running playr holds the lock; analysis runs beside it, a scan does not.
    let _running = playr_app::instance::claim_at(&dir.path().join("playr/instance.lock")).unwrap();
    let (code, stdout, stderr) = output(&db, &["analyze", "--jobs", "2"]);
    assert_eq!(code, Some(0), "{stderr}");
    assert!(stdout.contains("analysing 2 of 2 tracks"), "{stdout}");
    assert!(stdout.contains("padded"), "{stdout}");
    assert!(stdout.contains("16 of 24 bits used"), "{stdout}");
    assert!(stdout.contains("2 tracks analysed; 1 padded"), "{stdout}");
    let (code, _, stderr) = output(&db, &["scan", music.to_str().unwrap()]);
    assert_eq!(code, Some(1), "scan ran beside a playr: {stderr}");

    let (_, stdout, _) = output(&db, &["analyze"]);
    assert!(stdout.contains("analysing 0 of 2 tracks"), "{stdout}");
    let (_, stdout, _) = output(
        &db,
        &[
            "analyze",
            "--force",
            music.join("plain.wav").to_str().unwrap(),
        ],
    );
    assert!(stdout.contains("analysing 1 of 1 tracks"), "{stdout}");

    let (code, stdout, stderr) = output(&db, &["analyze", "--report", "--json"]);
    assert_eq!(code, Some(0), "{stderr}");
    let report: serde_json::Value = serde_json::from_str(&stdout).unwrap();
    let tracks = report["tracks"].as_array().unwrap();
    assert_eq!(tracks.len(), 2);
    for t in tracks {
        // A -12 dBFS sine at 421 Hz, where K-weighting is flat, in one
        // channel: -0.691 + 20 log10(0.25) - 3.01 = -15.74 LUFS.
        let lufs = t["loudness"].as_f64().unwrap();
        assert!((lufs + 15.74).abs() < 0.05, "{t}");
    }
    let padded = tracks
        .iter()
        .find(|t| t["path"].as_str().unwrap().ends_with("padded.wav"))
        .unwrap();
    assert_eq!(padded["findings"][0]["finding"], "padded");
    assert_eq!(report["not_analysed"], 0);
}

#[test]
fn playlists_go_out_and_come_back_as_m3u() {
    use playr_core::db::{self, query, Track};
    let dir = tempfile::tempdir().unwrap();
    let db_path = dir.path().join("library.db");
    let music = std::fs::canonicalize(dir.path()).unwrap().join("music");
    std::fs::create_dir(&music).unwrap();
    let conn = db::open(&db_path).unwrap();
    let ids: Vec<i64> = ["a.flac", "b.flac"]
        .iter()
        .map(|name| {
            let path = music.join(name);
            std::fs::write(&path, b"x").unwrap();
            let t = Track {
                path: path.to_string_lossy().into_owned(),
                mtime: 1,
                size: 1,
                ..Default::default()
            };
            db::upsert(&conn, &t).unwrap()
        })
        .collect();
    let mut conn = conn;
    query::save_playlist(&mut conn, "late", &[ids[1], ids[0]]).unwrap();
    drop(conn);
    let list = dir.path().join("late.m3u8");
    let list_arg = list.to_str().unwrap();

    let (code, out, _) = output(&db_path, &["export", "late"]);
    assert_eq!(code, Some(0));
    let b = music.join("b.flac");
    assert!(out.starts_with("#EXTM3U\n#PLAYLIST:late\n"), "{out}");
    assert!(out.find(b.to_str().unwrap()) < out.find("a.flac"), "{out}");

    assert_eq!(output(&db_path, &["export", "late", list_arg]).0, Some(0));
    let (code, _, err) = output(&db_path, &["export", "late", list_arg]);
    assert_eq!(code, Some(1));
    assert!(err.contains("exists; --force replaces it"), "{err}");
    assert_eq!(
        output(&db_path, &["export", "late", list_arg, "--force"]).0,
        Some(0)
    );

    // Its own export comes back only under another name.
    let (code, _, err) = output(&db_path, &["import", list_arg]);
    assert_eq!(code, Some(1));
    assert!(err.contains("a playlist named \"late\" exists"), "{err}");

    // Another player's list, with relative paths and an absolute one to a
    // track not in the library. `/elsewhere` would not do: without a drive
    // it is relative on Windows.
    let other = music.join("mix.m3u");
    let gone = dir.path().join("gone.flac");
    let text = format!("#EXTM3U\na.flac\n{}\nb.flac\n", gone.display());
    std::fs::write(&other, text).unwrap();
    let (code, out, _) = output(&db_path, &["import", other.to_str().unwrap()]);
    assert_eq!(code, Some(0));
    assert!(out.contains("saved \"mix\", 2 tracks"), "{out}");
    assert!(
        out.contains("1 not in the library") && out.contains("gone.flac"),
        "{out}"
    );
    let conn = db::open(&db_path).unwrap();
    let lists = query::playlists(&conn).unwrap();
    let mix = query::find_playlist(&lists, "mix").unwrap();
    let paths: Vec<String> = query::playlist_tracks(&conn, mix.id)
        .unwrap()
        .into_iter()
        .map(|t| t.path)
        .collect();
    assert_eq!(
        paths,
        [music.join("a.flac"), music.join("b.flac")].map(|p| p.to_string_lossy().into_owned())
    );

    let (code, out, _) = output(&db_path, &["import", list_arg, "--name", "late again"]);
    assert_eq!(code, Some(0), "{out}");
    assert!(output(
        &db_path,
        &["import", list_arg, other.to_str().unwrap(), "--name", "x"]
    )
    .2
    .contains("--name names one playlist"));
    // Neither command makes a library.
    let none = dir.path().join("none.db");
    assert!(output(&none, &["export", "late"])
        .2
        .contains("no library at"));
    assert!(output(&none, &["import", list_arg])
        .2
        .contains("no library at"));
    assert!(!none.exists());
}