File tree 4 files changed +64
-9
lines changed
4 files changed +64
-9
lines changed Original file line number Diff line number Diff line change @@ -99,17 +99,11 @@ function usage() {
99
99
}
100
100
101
101
const touched = [ ] ;
102
- if ( ! write ) {
102
+ if ( ! write && ! check ) {
103
103
const input = await fs . readFile ( files [ 0 ] , 'utf8' ) ;
104
104
const printed = await printDocument ( input ) ;
105
- if ( check ) {
106
- if ( printed !== input ) {
107
- touched . push ( files [ 0 ] ) ;
108
- }
109
- } else {
110
- // printDocument includes a newline
111
- process . stdout . write ( printed ) ;
112
- }
105
+ // printDocument includes a newline
106
+ process . stdout . write ( printed ) ;
113
107
} else {
114
108
for ( const file of files ) {
115
109
console . log ( `Processing ${ file } ` ) ;
Original file line number Diff line number Diff line change @@ -38,3 +38,31 @@ describe('ecmarkup#cli', function () {
38
38
} ) ;
39
39
} ) ;
40
40
} ) ;
41
+
42
+ describe ( 'emu-format --check' , function ( ) {
43
+ this . timeout ( 4000 ) ;
44
+
45
+ it ( 'exits cleanly if the file needs no formatting' , ( ) => {
46
+ execSync ( `${ execPath } ./bin/emu-format.js --check test/format-good.html` , {
47
+ encoding : 'utf8' ,
48
+ } ) ;
49
+ } ) ;
50
+
51
+ it ( 'exits with an error if the file needs formatting' , ( ) => {
52
+ assert . throws ( ( ) => {
53
+ execSync ( `${ execPath } ./bin/emu-format.js --check test/format-bad.html` , {
54
+ encoding : 'utf8' ,
55
+ } ) ;
56
+ } ) ;
57
+ } ) ;
58
+
59
+ it ( 'exits with an error if any files in the list need formatting' , ( ) => {
60
+ assert . throws ( ( ) => {
61
+ execSync (
62
+ `${ execPath } ./bin/emu-format.js --check test/format-good.html test/format-bad.html` , {
63
+ encoding : 'utf8' ,
64
+ } ,
65
+ ) ;
66
+ } ) ;
67
+ } ) ;
68
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ <meta charset =" utf-8" >
3
+ <link rel =" stylesheet" href =" css/elements.css" >
4
+ <script src =" ecmarkup.js" ></script >
5
+
6
+ <emu-clause id =" c1" >
7
+
8
+ <h1 >Clause Foo( _a_ , _b_ )</h1 >
9
+
10
+ <emu-alg >
11
+ 1. Call Foo(_a_ ).
12
+ 1. Call Bar(`toString` ).
13
+ 1. Call Baz(*true* ).
14
+ 1. Do something else.
15
+ 1. And again.
16
+ </emu-alg >
17
+ </emu-clause >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ <meta charset =" utf-8" >
3
+ <link rel =" stylesheet" href =" css/elements.css" >
4
+ <script src =" ecmarkup.js" ></script >
5
+
6
+ <emu-clause id =" c1" >
7
+ <h1 >Clause Foo(_a_ , _b_ )</h1 >
8
+
9
+ <emu-alg >
10
+ 1. Call Foo(_a_ ).
11
+ 1. Call Bar(`toString` ).
12
+ 1. Call Baz(*true* ).
13
+ 1. Do something else.
14
+ 1. And again.
15
+ </emu-alg >
16
+ </emu-clause >
You can’t perform that action at this time.
0 commit comments