Skip to content

Commit

Permalink
Run specs from within the spec directory
Browse files Browse the repository at this point in the history
This means all reported paths will be relative, which makes it much
easier to move specs without having to regenerate expected error
messages.
  • Loading branch information
nex3 committed Apr 6, 2019
1 parent c0caff6 commit 2d14d8f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/sass_spec/engine_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ def version

def compile(sass_filename, style, precision)
cmd = "#{@command} --precision #{precision} -t #{style || "expanded"}"
result = capture3_with_timeout("#{cmd} #{sass_filename}", :binmode => true, :timeout => @timeout)

dirname, basename = File.split(sass_filename)
result = Dir.chdir(dirname) do
capture3_with_timeout("#{File.absolute_path(cmd)} #{basename}",
binmode: true, timeout: @timeout)
end

if result[:timeout]
["", "Execution timed out after #{@timeout}s", -1]
Expand All @@ -79,6 +84,11 @@ def initialize(path)
main() async {
await for (var line in new LineSplitter().bind(utf8.decoder.bind(stdin))) {
if (line.startsWith("!cd ")) {
Directory.current = line.substring("!cd ".length);
continue;
}
try {
await sass.main(line.split(" ").where((arg) => arg.isNotEmpty).toList());
} catch (error, stackTrace) {
Expand Down Expand Up @@ -111,7 +121,9 @@ def version
end

def compile(sass_filename, style, precision)
@stdin.puts "--no-color --no-unicode --style #{style || 'expanded'} #{@args} #{sass_filename}"
dirname, basename = File.split(sass_filename)
@stdin.puts "!cd #{File.absolute_path(dirname)}"
@stdin.puts "--no-color --no-unicode --style #{style || 'expanded'} #{@args} #{basename}"
[next_chunk(@stdout), next_chunk(@stderr), next_chunk(@stdout).to_i]
end

Expand Down
1 change: 1 addition & 0 deletions lib/sass_spec/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def normalize_output(css)

# Normalizes the path names and whitespace in the given error message.
def normalize_error(error)
# TODO(nweiz): Delete path normalization when sass/libsass#2861 is fixed.
error.gsub(/(?:\/todo_|_todo\/)/, "/") # hide todo pre/suffix
.gsub(/\/libsass\-[a-z]+\-tests\//, "/") # hide test directory
.gsub(/\/libsass\-[a-z]+\-issues\//, "/libsass-issues/") # normalize issue specs
Expand Down

0 comments on commit 2d14d8f

Please sign in to comment.