@@ -67,15 +67,24 @@ def output
67
67
stdout , stderr , status = engine . compile ( @input_path , @output_style )
68
68
69
69
if @clean_test
70
- cleaned = _clean_output ( stdout )
70
+ clean_out = _clean_output ( stdout )
71
71
else
72
- cleaned = _norm_output ( stdout )
72
+ clean_out = _norm_output ( stdout )
73
73
end
74
- @output ||= [ stdout , cleaned , stderr , status ]
74
+
75
+ stderr = _clean_error ( stderr )
76
+ # always replace windows linefeeds
77
+ stdout = stdout . gsub ( /(\r \n )/ , "\n " )
78
+ stderr = stderr . gsub ( /(\r \n )/ , "\n " )
79
+
80
+ @output ||= [ stdout , clean_out , stderr , status ]
75
81
end
76
82
77
83
def expected
78
- output = File . read ( @expected_path , :encoding => "utf-8" )
84
+ output = File . read ( @expected_path , :binmode => true )
85
+ # we seem to get CP850 otherwise
86
+ # this provokes equal test to fail
87
+ output . force_encoding ( 'ASCII-8BIT' )
79
88
if @clean_test
80
89
@expected ||= _clean_output ( output )
81
90
else
@@ -84,12 +93,12 @@ def expected
84
93
end
85
94
86
95
def expected_error
87
- @expected_error = _clean_error ( File . read ( @error_path , :encoding => "utf-8" ) )
96
+ @expected_error = _clean_error ( File . read ( @error_path , :binmode => true ) )
88
97
end
89
98
90
99
def expected_status
91
100
if should_fail?
92
- @expected_status = File . read ( @status_path , :encoding => "utf-8" ) . to_i
101
+ @expected_status = File . read ( @status_path ) . to_i
93
102
else
94
103
@expected_status = 0
95
104
end
@@ -99,35 +108,39 @@ def engine
99
108
@options [ :engine_adapter ]
100
109
end
101
110
111
+ # normalization happens for every test
102
112
def _norm_output ( css )
103
- css = css . force_encoding ( 'iso-8859-1' ) . encode ( 'utf-8' )
104
- css . gsub ( /(?:\r ?\n )+/ , "\n " )
105
- . strip
113
+ # we dont want to test for linux or windows line-feeds
114
+ # but make sure we do not remove single cariage returns
115
+ css = css . gsub ( /(?:\r ?\n )+/ , "\n " )
116
+ end
117
+ def _norm_error ( err )
118
+ # we dont want to test for linux or windows line-feeds
119
+ # but make sure we do not remove single cariage returns
120
+ err = err . gsub ( /(?:\r ?\n )+/ , "\n " )
121
+ # remove all newlines at the end of the file
122
+ err = err . sub ( /(?:\r ?\n )+\z / , "" )
106
123
end
107
124
125
+ # cleaning only happens when requested for test
126
+ # done by creating `expected.type.clean` flag file
108
127
def _clean_output ( css )
109
- css = css . force_encoding ( 'iso-8859-1' ) . encode ( 'utf-8' )
110
- css . gsub ( /\s +/ , " " )
111
- . gsub ( / *\{ / , " {\n " )
128
+ css . gsub ( / *\{ / , " {\n " )
112
129
. gsub ( /([;,]) */ , "\\ 1\n " )
113
130
. gsub ( / *\} */ , " }\n " )
114
131
. gsub ( /;(?:\s *;)+/m , ";" )
115
132
. gsub ( /;\r ?\n }/m , " }" )
133
+ . gsub ( /\r ?\n / , "\n " )
134
+ . sub ( /(?:\r ?\n )+\z / , "" )
116
135
. strip
117
136
end
118
-
119
137
def _clean_error ( err )
120
- pwd = Dir . pwd
121
- url = pwd . gsub ( /\\ / , '/' )
122
- err = err . force_encoding ( 'iso-8859-1' ) . encode ( 'utf-8' )
123
- err . gsub ( /^.*?(input.scss:\d + DEBUG:)/ , '\1' )
124
- . gsub ( /[ ]+/ , " " )
125
- . gsub ( /#{ Regexp . quote ( url ) } \/ / , "/sass/sass-spec/" )
126
- . gsub ( /#{ Regexp . quote ( pwd ) } \/ / , "/sass/sass-spec/" )
127
- . gsub ( /(?:\/ todo_|_todo\/ )/ , "/" )
128
- . gsub ( /\/ libsass\- [a-z]+\- test\/ / , "/" )
129
- . gsub ( /\/ libsass\- [a-z]+\- issue/ , "/libsass-issue" )
130
- . strip
138
+ err . gsub ( /(?:\/ todo_|_todo\/ )/ , "/" ) # hide todo pre/suffix
139
+ . gsub ( /\/ libsass\- [a-z]+\- tests\/ / , "/" ) # hide test directory
140
+ . gsub ( /\/ libsass\- [a-z]+\- issues\/ / , "/libsass-issues/" ) # normalize issue specs
141
+ . gsub ( /[\w \/ \- \\ :]+?[\/ \\ ]spec[\/ \\ ]+/ , "/sass/spec/" ) # normalize abs paths
142
+ . sub ( /(?:\r ?\n )*\z / , "\n " ) # make sure we have exactly one trailing linefeed
143
+ . sub ( /\A (?:\r ?[\n \s ])+\z / , "" ) # clear the whole file if only whitespace
131
144
end
132
145
133
146
end
0 commit comments