Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test all output styles #270

Merged
merged 10 commits into from
Mar 12, 2015
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
5 changes: 4 additions & 1 deletion lib/sass_spec/cli.rb
Original file line number Diff line number Diff line change
@@ -17,7 +17,10 @@ def self.parse

# Constants
input_file: 'input.scss',
expected_file: 'expected_output.css'
expected_file: 'expected_output.css',
compressed_file: 'expected.compressed.css',
expanded_file: 'expected.expanded.css',
compact_file: 'expected.compact.css'
}

OptionParser.new do |opts|
4 changes: 2 additions & 2 deletions lib/sass_spec/engine_adapter.rb
Original file line number Diff line number Diff line change
@@ -44,8 +44,8 @@ def version
end


def compile(sass_filename)
Open3.capture3("#{@command} #{sass_filename}")
def compile(sass_filename, style)
Open3.capture3("#{@command} -t #{style} #{sass_filename}")
end
end

22 changes: 19 additions & 3 deletions lib/sass_spec/runner.rb
Original file line number Diff line number Diff line change
@@ -36,10 +36,26 @@ def _get_cases
cases = []
glob = File.join(@options[:spec_directory], "**", "#{@options[:input_file]}")
Dir.glob(glob) do |filename|
expected = Pathname.new(filename).dirname.join(@options[:expected_file])
input = Pathname.new(filename)
if filename.include?(@options[:filter])
cases.push SassSpec::TestCase.new(input.realpath(), expected.realpath(), @options)
expected = Pathname.new(filename).dirname.join(@options[:expected_file])
if File.file?(expected) && ! File.file?(expected.sub(/\.css$/, ".skip")) && filename.include?(@options[:filter])
clean = File.file?(expected.sub(/\.css$/, ".clean"))
cases.push SassSpec::TestCase.new(input.realpath(), expected.realpath(), "nested", clean, @options)
end
expanded = Pathname.new(filename).dirname.join(@options[:expanded_file])
if File.file?(expanded) && ! File.file?(expanded.sub(/\.css$/, ".skip")) && filename.include?(@options[:filter])
clean = File.file?(expanded.sub(/\.css$/, ".clean"))
cases.push SassSpec::TestCase.new(input.realpath(), expanded.realpath(), "expanded", clean, @options)
end
compressed = Pathname.new(filename).dirname.join(@options[:compressed_file])
if File.file?(compressed) && ! File.file?(compressed.sub(/\.css$/, ".skip")) && filename.include?(@options[:filter])
clean = File.file?(compressed.sub(/\.css$/, ".clean"))
cases.push SassSpec::TestCase.new(input.realpath(), compressed.realpath(), "compressed", clean, @options)
end
compact = Pathname.new(filename).dirname.join(@options[:compact_file])
if File.file?(compact) && ! File.file?(compact.sub(/\.css$/, ".skip")) && filename.include?(@options[:filter])
clean = File.file?(compact.sub(/\.css$/, ".clean"))
cases.push SassSpec::TestCase.new(input.realpath(), compact.realpath(), "compact", clean, @options)
end
end
cases
2 changes: 1 addition & 1 deletion lib/sass_spec/test.rb
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ class SassSpec::Test < Minitest::Test
parallelize_me!
def self.create_tests(test_cases, options = {})
test_cases[0..options[:limit]].each do |test_case|
define_method('test__' << test_case.name) do
define_method('test__' << test_case.output_style + "_" + test_case.name) do
run_spec_test(test_case, options)
end
end
34 changes: 30 additions & 4 deletions lib/sass_spec/test_case.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
# This represents a specific test case.
class SassSpec::TestCase
def initialize(input_scss, expected_css, options = {})
def initialize(input_scss, expected_css, style, clean, options = {})
@input_path = input_scss
@expected_path = expected_css
@output_style = style
@clean_test = clean
@options = options
end

def name
@input_path.dirname.to_s.sub(Dir.pwd + "/", "")
end

def clean_test
@clean_test
end

def output_style
@output_style
end

def input_path
@input_path
end
@@ -26,24 +36,40 @@ def output
if @output
return @output
end
stdout, stderr, status = engine.compile(@input_path)
cleaned = _clean_output(stdout)
stdout, stderr, status = engine.compile(@input_path, @output_style)
if @clean_test
cleaned = _clean_output(stdout)
else
cleaned = _norm_output(stdout)
end
@output ||= [stdout, cleaned, stderr, status]
end

def expected
@expected ||= _clean_output File.read(@expected_path)
if @clean_test
@expected ||= _clean_output File.read(@expected_path, :encoding => "utf-8")
else
@expected ||= _norm_output File.read(@expected_path, :encoding => "utf-8")
end
end

def engine
@options[:engine_adapter]
end

def _norm_output(css)
css = css.force_encoding('iso-8859-1').encode('utf-8')
css.gsub(/(?:\r?\n)+/, "\n")
.strip
end

def _clean_output(css)
css = css.force_encoding('iso-8859-1').encode('utf-8')
css.gsub(/\s+/, " ")
.gsub(/ *\{/, " {\n")
.gsub(/([;,]) */, "\\1\n")
.gsub(/ *\} */, " }\n")
.strip
end

end
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions spec/basic/01_simple_css/expected.compact.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a { color: blue; }
1 change: 1 addition & 0 deletions spec/basic/01_simple_css/expected.compressed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a{color:blue}
3 changes: 3 additions & 0 deletions spec/basic/01_simple_css/expected.expanded.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a {
color: blue;
}
1 change: 1 addition & 0 deletions spec/basic/02_simple_nesting/expected.compact.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
div img { border: 0px; }
1 change: 1 addition & 0 deletions spec/basic/02_simple_nesting/expected.compressed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
div img{border:0px}
3 changes: 3 additions & 0 deletions spec/basic/02_simple_nesting/expected.expanded.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
div img {
border: 0px;
}
1 change: 1 addition & 0 deletions spec/basic/03_simple_variable/expected.compact.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a { color: red; }
1 change: 1 addition & 0 deletions spec/basic/03_simple_variable/expected.compressed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a{color:red}
3 changes: 3 additions & 0 deletions spec/basic/03_simple_variable/expected.expanded.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a {
color: red;
}
5 changes: 5 additions & 0 deletions spec/basic/04_basic_variables/expected.compact.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a { color: red; background: "blue"; }

foo { a: 1 2 before; }

foo { a: 1 2 before; }
1 change: 1 addition & 0 deletions spec/basic/04_basic_variables/expected.compressed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a{color:red;background:"blue"}foo{a:1 2 before}foo{a:1 2 before}
12 changes: 12 additions & 0 deletions spec/basic/04_basic_variables/expected.expanded.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
a {
color: red;
background: "blue";
}

foo {
a: 1 2 before;
}

foo {
a: 1 2 before;
}
9 changes: 9 additions & 0 deletions spec/basic/05_empty_levels/expected.compact.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
div span { color: red; background: blue; }

div { color: gray; }
div empty span { color: red; background: blue; }

empty1 empty2 div { blah: blah; }

empty1 empty2 div { bloo: blee; }
empty1 empty2 div empty3 span { blah: blah; blah: blah; }
1 change: 1 addition & 0 deletions spec/basic/05_empty_levels/expected.compressed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
div span{color:red;background:blue}div{color:gray}div empty span{color:red;background:blue}empty1 empty2 div{blah:blah}empty1 empty2 div{bloo:blee}empty1 empty2 div empty3 span{blah:blah;blah:blah}
24 changes: 24 additions & 0 deletions spec/basic/05_empty_levels/expected.expanded.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
div span {
color: red;
background: blue;
}

div {
color: gray;
}
div empty span {
color: red;
background: blue;
}

empty1 empty2 div {
blah: blah;
}

empty1 empty2 div {
bloo: blee;
}
empty1 empty2 div empty3 span {
blah: blah;
blah: blah;
}
13 changes: 13 additions & 0 deletions spec/basic/06_nesting_and_comments/expected.compact.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* top level comment -- should be preserved */
div { /* another comment that should be preserved */ color: red; background: blue; /* the next selector should be indented two spaces */ margin: 10px 5px; }
div span { font-weight: bold; /* yet another comment that should be preserved */ display: inline-block; }
div span a { text-decoration: none; /* where will this comment go? */ color: green; /* what about this comment? */ border: 1px bloo blee red; }
div empty not_empty { blah: blah; bloo: bloo; }
div p { padding: 10px 8%; -webkit-box-sizing: hux; }
div h1 { color: "a 'red' and \"blue\" value"; }

/* last comment, top level again -- compare the indentation! */
div { f: g; }
div empty span { a: b; }
div empty_with_comment { /* hey now */ }
div empty_with_comment span { c: d; }
1 change: 1 addition & 0 deletions spec/basic/06_nesting_and_comments/expected.compressed.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions spec/basic/06_nesting_and_comments/expected.expanded.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* top level comment -- should be preserved */
div {
/* another comment that should be preserved */
color: red;
background: blue;
/* the next selector should be indented two spaces */
margin: 10px 5px;
}
div span {
font-weight: bold;
/* yet another comment that should be preserved */
display: inline-block;
}
div span a {
text-decoration: none;
/* where will this comment go? */
color: green;
/* what about this comment? */
border: 1px bloo blee red;
}
div empty not_empty {
blah: blah;
bloo: bloo;
}
div p {
padding: 10px 8%;
-webkit-box-sizing: hux;
}
div h1 {
color: "a 'red' and \"blue\" value";
}

/* last comment, top level again --
compare the indentation! */
div {
f: g;
}
div empty span {
a: b;
}
div empty_with_comment {
/* hey now */
}
div empty_with_comment span {
c: d;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
a, b { color: red; background: blue; }

c, d { color: gray; }
c e, c f, d e, d f { background: blue; padding: 10px 5px; }
c g, c h, d g, d h { blah: blah; bloo: bloo; }
c i, c j, d i, d j { foo: goo; }
c i k, c i l, c j k, c j l, d i k, d i l, d j k, d j l { hoo: boo; }
c i k m, c i k n, c i k o, c i l m, c i l n, c i l o, c j k m, c j k n, c j k o, c j l m, c j l n, c j l o, d i k m, d i k n, d i k o, d i l m, d i l n, d i l o, d j k m, d j k n, d j k o, d j l m, d j l n, d j l o { wow: we are far inside; but: it still works; }

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions spec/basic/07_nested_simple_selector_groups/expected.expanded.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
a, b {
color: red;
background: blue;
}

c, d {
color: gray;
}
c e, c f, d e, d f {
background: blue;
padding: 10px 5px;
}
c g, c h, d g, d h {
blah: blah;
bloo: bloo;
}
c i, c j, d i, d j {
foo: goo;
}
c i k, c i l, c j k, c j l, d i k, d i l, d j k, d j l {
hoo: boo;
}
c i k m, c i k n, c i k o, c i l m, c i l n, c i l o, c j k m, c j k n, c j k o, c j l m, c j l n, c j l o, d i k m, d i k n, d i k o, d i l m, d i l n, d i l o, d j k m, d j k n, d j k o, d j l m, d j l n, d j l o {
wow: we are far inside;
but: it still works;
}
2 changes: 2 additions & 0 deletions spec/basic/08_selector_combinators/expected.compact.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a + b > c { color: red; background: gray; }
a + b > c d e { color: blue; background: white; }
1 change: 1 addition & 0 deletions spec/basic/08_selector_combinators/expected.compressed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a+b>c{color:red;background:gray}a+b>c d e{color:blue;background:white}
8 changes: 8 additions & 0 deletions spec/basic/08_selector_combinators/expected.expanded.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
a + b > c {
color: red;
background: gray;
}
a + b > c d e {
color: blue;
background: white;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a + b, c { blah: blah; bleh: bleh; }
a + b d e, a + b f ~ g + h, a + b > i, c d e, c f ~ g + h, c > i { bloo: bloo; blee: blee; }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a+b,c{blah:blah;bleh:bleh}a+b d e,a+b f ~ g+h,a+b>i,c d e,c f ~ g+h,c>i{bloo:bloo;blee:blee}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
a + b, c {
blah: blah;
bleh: bleh;
}
a + b d e, a + b f ~ g + h, a + b > i, c d e, c f ~ g + h, c > i {
bloo: bloo;
blee: blee;
}
2 changes: 2 additions & 0 deletions spec/basic/10_classes_and_ids/expected.compact.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a + b, .class { blah: blah; bleh: bleh; }
a + b d #id, a + b f ~ g.other + h, a + b > i#grar, .class d #id, .class f ~ g.other + h, .class > i#grar { bloo: bloo; blee: blee; }
1 change: 1 addition & 0 deletions spec/basic/10_classes_and_ids/expected.compressed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a+b,.class{blah:blah;bleh:bleh}a+b d #id,a+b f ~ g.other+h,a+b>i#grar,.class d #id,.class f ~ g.other+h,.class>i#grar{bloo:bloo;blee:blee}
8 changes: 8 additions & 0 deletions spec/basic/10_classes_and_ids/expected.expanded.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
a + b, .class {
blah: blah;
bleh: bleh;
}
a + b d #id, a + b f ~ g.other + h, a + b > i#grar, .class d #id, .class f ~ g.other + h, .class > i#grar {
bloo: bloo;
blee: blee;
}
2 changes: 2 additions & 0 deletions spec/basic/11_attribute_selectors/expected.compact.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[hey='ho'], a > b { blah: blah; }
[hey='ho'] c, [hey='ho'] [hoo*="ha"], a > b c, a > b [hoo*="ha"] { bloo: bloo; }
1 change: 1 addition & 0 deletions spec/basic/11_attribute_selectors/expected.compressed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[hey='ho'],a>b{blah:blah}[hey='ho'] c,[hey='ho'] [hoo*="ha"],a>b c,a>b [hoo*="ha"]{bloo:bloo}
6 changes: 6 additions & 0 deletions spec/basic/11_attribute_selectors/expected.expanded.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[hey='ho'], a > b {
blah: blah;
}
[hey='ho'] c, [hey='ho'] [hoo*="ha"], a > b c, a > b [hoo*="ha"] {
bloo: bloo;
}
2 changes: 2 additions & 0 deletions spec/basic/13_back_references/expected.compact.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hey, ho { blah: blah; }
hey > boo, foo hey.goo, ho > boo, foo ho.goo { bloo: bloo; }
1 change: 1 addition & 0 deletions spec/basic/13_back_references/expected.compressed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hey,ho{blah:blah}hey>boo,foo hey.goo,ho>boo,foo ho.goo{bloo:bloo}
6 changes: 6 additions & 0 deletions spec/basic/13_back_references/expected.expanded.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
hey, ho {
blah: blah;
}
hey > boo, foo hey.goo, ho > boo, foo ho.goo {
bloo: bloo;
}
7 changes: 7 additions & 0 deletions spec/basic/14_imports/expected.compact.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
div span { moo: goo; }

foo { blah: blah; }
foo goo { blee: blee; hello: world; }
foo goo hoo { mux: scooba-dee-doo; flux: gooboo boo; }
foo goo hoo d { inside: d now; }
foo blux { hey: another thing; ho: will this work; }
1 change: 1 addition & 0 deletions spec/basic/14_imports/expected.compressed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
div span{moo:goo}foo{blah:blah}foo goo{blee:blee;hello:world}foo goo hoo{mux:scooba-dee-doo;flux:gooboo boo}foo goo hoo d{inside:d now}foo blux{hey:another thing;ho:will this work}
Loading