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
|
//! ref: composer/tests/Composer/Test/Command/ExecCommandTest.php
use crate::test_case::{RunOptions, get_application_tester, init_temp_composer};
use serial_test::serial;
use shirabe_php_shim::PhpMixed;
/// ref: ExecCommandTest::testListThrowsIfNoBinariesExist
#[test]
#[serial]
fn test_list_throws_if_no_binaries_exist() {
let tear_down = init_temp_composer(Some(&serde_json::json!({})), None, None, false);
let composer_dir = tear_down.working_dir();
let composer_bin_dir = format!("{}/vendor/bin", composer_dir.display());
let mut app_tester = get_application_tester();
let err = app_tester
.run(
vec![
(PhpMixed::from("command"), PhpMixed::from("exec")),
(PhpMixed::from("--list"), PhpMixed::from(true)),
],
RunOptions::default(),
)
.expect_err("exec --list with no binaries should raise a RuntimeException");
assert!(
err.to_string().contains(&format!(
"No binaries found in composer.json or in bin-dir ({})",
composer_bin_dir
)),
"expected RuntimeException about no binaries, got: {:?}",
err.to_string(),
);
drop(tear_down);
}
/// ref: ExecCommandTest::testList
#[test]
#[serial]
fn test_list() {
let tear_down = init_temp_composer(
Some(&serde_json::json!({
"bin": [
"a",
],
})),
None,
None,
false,
);
let composer_dir = tear_down.working_dir();
let composer_bin_dir = format!("{}/vendor/bin", composer_dir.display());
std::fs::create_dir_all(&composer_bin_dir).unwrap();
std::fs::write(format!("{}/b", composer_bin_dir), "").unwrap();
std::fs::write(format!("{}/b.bat", composer_bin_dir), "").unwrap();
std::fs::write(format!("{}/c", composer_bin_dir), "").unwrap();
let mut app_tester = get_application_tester();
app_tester
.run(
vec![
(PhpMixed::from("command"), PhpMixed::from("exec")),
(PhpMixed::from("--list"), PhpMixed::from(true)),
],
RunOptions::default(),
)
.unwrap();
let output = app_tester.get_display();
assert_eq!("Available binaries:\n- b\n- c\n- a (local)", output.trim());
drop(tear_down);
}
|