@@ -17,6 +17,30 @@ test('no args', t => {
1717 t . is ( result . code , 1 ) ;
1818} ) ;
1919
20+ test ( 'line count option without a value or files' , t => {
21+ const result = shell . head ( '-n' ) ;
22+ t . is ( result . code , 1 ) ;
23+ t . is ( result . stderr , 'head: no paths given' ) ;
24+ } ) ;
25+
26+ test ( 'zero line count still requires files or piped input' , t => {
27+ const result = shell . head ( '-n' , 0 ) ;
28+ t . is ( result . code , 1 ) ;
29+ t . is ( result . stderr , 'head: no paths given' ) ;
30+ } ) ;
31+
32+ test ( 'positive line count still requires files or piped input' , t => {
33+ const result = shell . head ( '-n' , 1 ) ;
34+ t . is ( result . code , 1 ) ;
35+ t . is ( result . stderr , 'head: no paths given' ) ;
36+ } ) ;
37+
38+ test ( 'negative line count still requires files or piped input' , t => {
39+ const result = shell . head ( '-n' , - 1 ) ;
40+ t . is ( result . code , 1 ) ;
41+ t . is ( result . stderr , 'head: no paths given' ) ;
42+ } ) ;
43+
2044test ( 'file does not exist' , t => {
2145 t . falsy ( fs . existsSync ( '/asdfasdf' ) ) ; // sanity check
2246 const result = shell . head ( '/asdfasdf' ) ; // file does not exist
@@ -53,6 +77,79 @@ test('simple', t => {
5377 t . is ( result . toString ( ) , topOfFile1 . slice ( 0 , 10 ) . join ( '\n' ) + '\n' ) ;
5478} ) ;
5579
80+ test ( 'zero lines with separate option' , t => {
81+ const result = shell . head ( '-n' , 0 , 'test/resources/head/shortfile1' ) ;
82+ t . falsy ( shell . error ( ) ) ;
83+ t . is ( result . code , 0 ) ;
84+ t . is ( result . toString ( ) , '' ) ;
85+ } ) ;
86+
87+ test ( 'zero lines from multiple files' , t => {
88+ const result = shell . head ( '-n' , 0 , 'test/resources/head/shortfile1' ,
89+ 'test/resources/file1' ) ;
90+ t . falsy ( shell . error ( ) ) ;
91+ t . is ( result . code , 0 ) ;
92+ t . is ( result . toString ( ) , '' ) ;
93+ } ) ;
94+
95+ test ( 'zero lines with array syntax' , t => {
96+ const result = shell . head ( '-n' , 0 , [ 'test/resources/head/shortfile1' ,
97+ 'test/resources/file1' ] ) ;
98+ t . falsy ( shell . error ( ) ) ;
99+ t . is ( result . code , 0 ) ;
100+ t . is ( result . toString ( ) , '' ) ;
101+ } ) ;
102+
103+ test ( 'zero lines with object option' , t => {
104+ const result = shell . head ( { '-n' : 0 } , 'test/resources/head/shortfile1' ,
105+ 'test/resources/file1' ) ;
106+ t . falsy ( shell . error ( ) ) ;
107+ t . is ( result . code , 0 ) ;
108+ t . is ( result . toString ( ) , '' ) ;
109+ } ) ;
110+
111+ test ( 'numeric zero lines from a pipe' , t => {
112+ const result = shell . ShellString ( 'first\nlast\n' ) . head ( '-n' , 0 ) ;
113+ t . falsy ( shell . error ( ) ) ;
114+ t . is ( result . code , 0 ) ;
115+ t . is ( result . toString ( ) , '' ) ;
116+ } ) ;
117+
118+ test ( 'string zero lines from a pipe' , t => {
119+ const result = shell . ShellString ( 'first\nlast\n' ) . head ( '-n' , '0' ) ;
120+ t . falsy ( shell . error ( ) ) ;
121+ t . is ( result . code , 0 ) ;
122+ t . is ( result . toString ( ) , '' ) ;
123+ } ) ;
124+
125+ test ( 'negative string zero lines from a pipe' , t => {
126+ const result = shell . ShellString ( 'first\nlast\n' ) . head ( '-n' , '-0' ) ;
127+ t . falsy ( shell . error ( ) ) ;
128+ t . is ( result . code , 0 ) ;
129+ t . is ( result . toString ( ) , '' ) ;
130+ } ) ;
131+
132+ test ( 'positive string zero lines from a pipe' , t => {
133+ const result = shell . ShellString ( 'first\nlast\n' ) . head ( '-n' , '+0' ) ;
134+ t . falsy ( shell . error ( ) ) ;
135+ t . is ( result . code , 0 ) ;
136+ t . is ( result . toString ( ) , '' ) ;
137+ } ) ;
138+
139+ test ( 'zero lines still reports missing files' , t => {
140+ const result = shell . head ( '-n' , 0 , '/asdfasdf' ) ;
141+ t . truthy ( shell . error ( ) ) ;
142+ t . is ( result . code , 1 ) ;
143+ t . is ( result . stderr , 'head: no such file or directory: /asdfasdf' ) ;
144+ } ) ;
145+
146+ test ( 'zero lines still reports directories' , t => {
147+ const result = shell . head ( '-n' , 0 , 'test/resources/' ) ;
148+ t . truthy ( shell . error ( ) ) ;
149+ t . is ( result . code , 1 ) ;
150+ t . is ( result . stderr , "head: error reading 'test/resources/': Is a directory" ) ;
151+ } ) ;
152+
56153test ( 'multiple files' , t => {
57154 const result = shell . head ( 'test/resources/head/file2.txt' ,
58155 'test/resources/head/file1.txt' ) ;
0 commit comments