1
1
use assert_cmd:: Command ;
2
- use std:: fs;
3
- use test_case:: test_case;
4
2
5
3
fn css_inline ( ) -> Command {
6
4
Command :: cargo_bin ( "css-inline" ) . unwrap ( )
7
5
}
8
6
9
- #[ test]
10
- fn success ( ) {
11
- css_inline ( )
12
- . arg ( "tests/example.html" )
13
- . arg ( "--output-filename-prefix=keep-style-tags." )
14
- . assert ( )
15
- . success ( )
16
- . stdout ( "tests/example.html: SUCCESS\n " ) ;
17
- let content = fs:: read_to_string ( "tests/keep-style-tags.example.html" ) . unwrap ( ) ;
18
- assert_eq ! (
19
- content,
20
- "<html><head>\n \
7
+ #[ cfg( feature = "cli" ) ]
8
+ pub mod tests {
9
+ use super :: css_inline;
10
+ use std:: fs;
11
+ use test_case:: test_case;
12
+
13
+ #[ test]
14
+ fn success ( ) {
15
+ css_inline ( )
16
+ . arg ( "tests/example.html" )
17
+ . arg ( "--output-filename-prefix=keep-style-tags." )
18
+ . assert ( )
19
+ . success ( )
20
+ . stdout ( "tests/example.html: SUCCESS\n " ) ;
21
+ let content = fs:: read_to_string ( "tests/keep-style-tags.example.html" ) . unwrap ( ) ;
22
+ assert_eq ! (
23
+ content,
24
+ "<html><head>\n \
21
25
\n \
22
26
\n \
23
27
\n \
@@ -26,80 +30,96 @@ fn success() {
26
30
<a class=\" test-class\" href=\" https://example.com\" style=\" color: #ffffff;\" >Test</a>\n \
27
31
<h1 style=\" text-decoration: none;\" >Test</h1>\n \n \n \
28
32
</body></html>"
29
- )
30
- }
33
+ )
34
+ }
31
35
32
- #[ test]
33
- fn keep_style_tags ( ) {
34
- css_inline ( )
35
- . arg ( "tests/example.html" )
36
- . arg ( "--keep-style-tags" )
37
- . assert ( )
38
- . success ( )
39
- . stdout ( "tests/example.html: SUCCESS\n " ) ;
40
- let content = fs:: read_to_string ( "tests/inlined.example.html" ) . unwrap ( ) ;
41
- assert_eq ! (
42
- content,
43
- "<html><head>\n \n \
36
+ #[ test]
37
+ fn keep_style_tags ( ) {
38
+ css_inline ( )
39
+ . arg ( "tests/example.html" )
40
+ . arg ( "--keep-style-tags" )
41
+ . assert ( )
42
+ . success ( )
43
+ . stdout ( "tests/example.html: SUCCESS\n " ) ;
44
+ let content = fs:: read_to_string ( "tests/inlined.example.html" ) . unwrap ( ) ;
45
+ assert_eq ! (
46
+ content,
47
+ "<html><head>\n \n \
44
48
<style>\n h1 {\n text-decoration: none;\n }\n </style>\n \
45
49
<style>\n .test-class {\n color: #ffffff;\n }\n \n a {\n color: #17bebb;\n }\n </style>\n \
46
50
</head>\n \
47
51
<body>\n \
48
52
<a class=\" test-class\" href=\" https://example.com\" style=\" color: #ffffff;\" >Test</a>\n \
49
53
<h1 style=\" text-decoration: none;\" >Test</h1>\n \n \n \
50
54
</body></html>"
51
- )
52
- }
55
+ )
56
+ }
53
57
54
- #[ test]
55
- fn wrong_base_url ( ) {
56
- css_inline ( )
57
- . arg ( "--base-url=https://:::::" )
58
- . write_stdin ( r#"<html><head><title>Test</title><link href="external.css" rel="stylesheet" type="text/css"></head><body><h1>Hello world!</h1></body></html>"# )
59
- . assert ( )
60
- . failure ( )
61
- . stderr ( "Status: ERROR\n Details: empty host\n " ) ;
62
- }
58
+ #[ test]
59
+ fn wrong_base_url ( ) {
60
+ css_inline ( )
61
+ . arg ( "--base-url=https://:::::" )
62
+ . write_stdin ( r#"<html><head><title>Test</title><link href="external.css" rel="stylesheet" type="text/css"></head><body><h1>Hello world!</h1></body></html>"# )
63
+ . assert ( )
64
+ . failure ( )
65
+ . stderr ( "Status: ERROR\n Details: empty host\n " ) ;
66
+ }
63
67
64
- #[ test]
65
- fn not_found ( ) {
66
- css_inline ( ) . arg ( "unknown.html" ) . assert ( ) . failure ( ) . stderr (
67
- "Filename: unknown.html\n Status: ERROR\n Details: No such file or directory (os error 2)\n " ,
68
- ) ;
69
- }
68
+ #[ test]
69
+ fn not_found ( ) {
70
+ css_inline ( ) . arg ( "unknown.html" ) . assert ( ) . failure ( ) . stderr (
71
+ "Filename: unknown.html\n Status: ERROR\n Details: No such file or directory (os error 2)\n " ,
72
+ ) ;
73
+ }
70
74
71
- #[ test]
72
- fn invalid_css ( ) {
73
- css_inline ( )
74
- . write_stdin ( r#"<html><head><title>Test</title><style>h1 {background-color: blue;}</style></head><body><h1 style="@wrong { color: ---}">Hello world!</h1></body></html>"# )
75
- . assert ( )
76
- . failure ( )
77
- . stderr ( "Status: ERROR\n Details: Invalid @ rule: wrong\n " ) ;
78
- }
75
+ #[ test]
76
+ fn invalid_css ( ) {
77
+ css_inline ( )
78
+ . write_stdin ( r#"<html><head><title>Test</title><style>h1 {background-color: blue;}</style></head><body><h1 style="@wrong { color: ---}">Hello world!</h1></body></html>"# )
79
+ . assert ( )
80
+ . failure ( )
81
+ . stderr ( "Status: ERROR\n Details: Invalid @ rule: wrong\n " ) ;
82
+ }
79
83
80
- #[ test]
81
- fn invalid_css_in_file ( ) {
82
- css_inline ( )
83
- . arg ( "tests/invalid-example.html" )
84
- . assert ( )
85
- . failure ( )
86
- . stderr (
87
- "Filename: tests/invalid-example.html\n Status: ERROR\n Details: Invalid @ rule: wrong\n " ,
88
- ) ;
89
- }
84
+ #[ test]
85
+ fn invalid_css_in_file ( ) {
86
+ css_inline ( )
87
+ . arg ( "tests/invalid-example.html" )
88
+ . assert ( )
89
+ . failure ( )
90
+ . stderr (
91
+ "Filename: tests/invalid-example.html\n Status: ERROR\n Details: Invalid @ rule: wrong\n " ,
92
+ ) ;
93
+ }
90
94
91
- #[ test]
92
- fn stdin ( ) {
93
- css_inline ( )
94
- . write_stdin ( r#"<html><head><title>Test</title><style>h1 {background-color: blue;}</style></head><body><h1>Hello world!</h1></body></html>"# )
95
- . assert ( )
96
- . success ( )
97
- . stdout ( "<html><head><title>Test</title></head><body><h1 style=\" background-color: blue;\" >Hello world!</h1></body></html>" ) ;
95
+ #[ test]
96
+ fn stdin ( ) {
97
+ css_inline ( )
98
+ . write_stdin ( r#"<html><head><title>Test</title><style>h1 {background-color: blue;}</style></head><body><h1>Hello world!</h1></body></html>"# )
99
+ . assert ( )
100
+ . success ( )
101
+ . stdout ( "<html><head><title>Test</title></head><body><h1 style=\" background-color: blue;\" >Hello world!</h1></body></html>" ) ;
102
+ }
103
+
104
+ #[ test_case( "--help" , "css-inline inlines CSS into HTML documents." ) ]
105
+ #[ test_case( "--version" , "css-inline 0.9.0" ) ]
106
+ fn args ( arg : & str , expected : & str ) {
107
+ let stdout = css_inline ( ) . arg ( arg) . assert ( ) . success ( ) . to_string ( ) ;
108
+ assert ! ( stdout. contains( expected) , "{}" , stdout) ;
109
+ }
98
110
}
99
111
100
- #[ test_case( "--help" , "css-inline inlines CSS into HTML documents." ) ]
101
- #[ test_case( "--version" , "css-inline 0.9.0" ) ]
102
- fn args ( arg : & str , expected : & str ) {
103
- let stdout = css_inline ( ) . arg ( arg) . assert ( ) . success ( ) . to_string ( ) ;
104
- assert ! ( stdout. contains( expected) , "{}" , stdout) ;
112
+ #[ cfg( not( feature = "cli" ) ) ]
113
+ pub mod tests {
114
+ use super :: css_inline;
115
+
116
+ #[ test]
117
+ fn test_no_cli_feature ( ) {
118
+ let cmd = css_inline ( ) . assert ( ) . failure ( ) ;
119
+ let stdout = & cmd. get_output ( ) . stderr ;
120
+ assert_eq ! (
121
+ stdout,
122
+ b"`css-inline` CLI is only available with the `cli` feature\n "
123
+ ) ;
124
+ }
105
125
}
0 commit comments