Skip to content

Commit

Permalink
Fix Windows specs
Browse files Browse the repository at this point in the history
  • Loading branch information
janbiedermann authored and hmdne committed Nov 17, 2022
1 parent 6381a11 commit 076bf7e
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
@@ -1 +1,5 @@
UNRELEASED.md merge=union
spec/opal/core/language/DATA/characters_support_crlf_spec.rb text eol=crlf
spec/opal/core/language/DATA/characters_support_spec.rb text eol=lf
spec/opal/core/language/DATA/multiple___END___crlf_spec.rb text eol=crlf
spec/opal/core/language/DATA/multiple___END___spec.rb text eol=lf
15 changes: 13 additions & 2 deletions .github/workflows/build.yml
Expand Up @@ -45,9 +45,20 @@ jobs:
- name: smoke-test
ruby: '3.0'
command: bin/rake smoke_test
- name: windows-mspec-nodejs
command: bundle exec rake mspec_nodejs
ruby: '3.0'
os: windows-latest
- name: windows-mspec-chrome
command: bundle exec rake mspec_chrome
ruby: '3.0'
os: windows-latest
- name: windows-minitest
command: bundle exec rake minitest
ruby: '3.0'
os: windows-latest
- name: windows
# These two fail because of broken stacktraces on windows: minitest_node_nodejs mspec_nodejs
command: bundle exec rake rspec minitest_nodejs
command: bundle exec rake rspec
ruby: '3.0'
os: windows-latest
- name: lint
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -18,14 +18,14 @@
<a href="#sponsors"><img src="https://opencollective.com/opal/sponsors/badge.svg" alt="Sponsors on Open Collective" title="" /></a>
<a href="https://slack.opalrb.com/"><img src="https://img.shields.io/badge/slack-join%20chat-46BC99?logo=slack&style=flat" alt="Slack" title="Join Chat" /></a>
<a href="https://opalrb.com/docs"><img src="https://img.shields.io/badge/docs-updated-blue.svg" alt="Documentation" title="" /></a>

<br>
<strong>Code:</strong><br>
<a href="https://badge.fury.io/rb/opal"><img src="https://img.shields.io/gem/v/opal.svg?style=flat" alt="Gem Version" title="" /></a>
<a href="https://github.com/opal/opal/actions?query=workflow%3Abuild"><img src="https://github.com/opal/opal/workflows/build/badge.svg" alt="Build Status" /></a>
<a href="https://codeclimate.com/github/opal/opal"><img src="https://img.shields.io/codeclimate/maintainability-percentage/opal/opal.svg" alt="Code Climate" title="" /></a>
<a href="https://coveralls.io/github/opal/opal?branch=master"><img src="https://coveralls.io/repos/opal/opal/badge.svg?branch=master&amp;service=github" alt="Coverage Status" title="" /></a>

<br>
<strong>Sponsors:</strong>
<br/><a href="https://nebulab.it?utm_source=github&utm_medium=badge"><img src="https://img.shields.io/static/v1?label=Nebulab&message=Open+Source+Fridays&color=%235dbefd&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMQSURBVHgBrZZNTxNRFIbfczsgIMQiLBCRFDaGhUr9A9iiIa5EEneIwE/AlRsNv8KlIKwFl35RTUBX8rFBdiVKAgqmXSCY0M71nJl+zJTOdKh9k6Yzc8/cZ86555x7CQE0mji5hSyGlQoNaOgIPwrnhtIArWszu4EQFudjdR8rzUV+gw8/ZMZB9IwvIwimJJGafhmjWZwFOJ7QkYzWCwTdj+qUDJGKz8Rou3RAlT4YS+hHWW2u/QdM1MNzrI6+zwyXDrg8FANStIDaSXOIJ5whLgAljOIZiglRK6U4vDfz4S2ElGGJWsEaQkCTUbhtNbV+lb+xgFY2Bs9ET0h/GzBxlfAkqnCUKY5xKfVLbsi1/R126lcF6WgCYp2ES42EBp6tvQFY+alLTUlrUxizJEVNWiVwBkVagGg7oe+CDclLYOfrgMdfTBz8PfWa1lkzbsDEsH/5FyF9YUK0zQ1xwpoZtsm9pwxMRLyA9wyi0A2Jcjl1NNqeeEFEimxYPkmWd014ikIDnDTeBb53DOweaRxnvWGyhnmYfPZWGt487sNi6lsK67/lZ1oZGOtUaD3nhtU7etXXfe0VzrzCBgLKCR68rNDX6oaJlvd0xXnklbSfgSTL/QghXF8EP980cVKyVL/Ys9UDVFJa8Tdt+1lYmcmJM3Vd4UEvWeslRf32h9ubrVRl77gBrCto85OfUU+LXTMGx+JuN2Hoin3/Zkfjj6ObBAknV+KG4jpc9BqXMEpiCMz6Z9ZQ12kvJZxb6co4Zr1W83esY8F2OYsIe+eEyfTiVXczCl7uM2wliHfMEJaRc3Wa++mLUotrF4EW7h6f94Dvh6aVFM60Fy8Xkya+BfBOjh5yUWhqY0vmKi9q1GnVxZ7sHKIWSs7FQ71yUagkRTTCfymnVY1gsgHHC5z8hbUjaz0Fr8ZanXhX0pPOw5SrV8wNGjNscMrTKpXKaj05f9twVYHnMZGPHEuwTwEBNi+3NGiNt6GRcsfEIAfhp2cAV3cQLtXoOz7q8+ZJRLx3kmxn4dy7aas1SrfiBpKraV/9A+PSJLDAXLUvAAAAAElFTkSuQmCC" alt="Nebulab: Open Source Fridays" /></a>
Expand Down Expand Up @@ -99,7 +99,7 @@ or to build an entire app including dependencies declared with `require`:
```ruby
builder = Opal::Builder.new
builder.build_str('require "opal"; puts "wow"', '(inline)')
File.write 'app.js', builder.to_s
File.binwrite 'app.js', builder.to_s # must use binary mode for writing
```


Expand Down
10 changes: 5 additions & 5 deletions docs/jquery.md
Expand Up @@ -58,7 +58,7 @@ builder.build('opal')
builder.build('opal-jquery')
builder.build('./app/application.rb')

File.write('application.js', builder.to_s)
File.binwrite('application.js', builder.to_s) # must use binary mode for writing
```

then simply load the compiled file in your html:
Expand All @@ -67,19 +67,19 @@ then simply load the compiled file in your html:
<!DOCTYPE html>
<html>
<head>
<script src='https://code.jquery.com/jquery-3.3.1.min.js' integrity='sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=' crossorigin='anonymous'></script>
<script src='https://code.jquery.com/jquery-3.3.1.min.js' integrity='sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=' crossorigin='anonymous'></script>
<script type='text/javascript' src='./application.js'></script>
</head>
<body></body>
</html>
```

NOTE: opal-jquery expects a jquery library to be loaded. This example loads it
remotely from jquery.com, but a locally downloaded copy works just as well, or-
remotely from jquery.com, but a locally downloaded copy works just as well, or-
if you're using rails- jquery may be included automatically.

This example builds opal, opal-jquery and the application into a single `.js` file,
but you may build them separately, if you so choose. Just remember to include
This example builds opal, opal-jquery and the application into a single `.js` file,
but you may build them separately, if you so choose. Just remember to include
each respective script in your html!

### How does opal-jquery work
Expand Down
12 changes: 6 additions & 6 deletions lib/opal/cli_runners/chrome.rb
Expand Up @@ -66,17 +66,17 @@ def run
def prepare_files_in(dir)
js = builder.to_s
map = builder.source_map.to_json
stack = File.read("#{__dir__}/source-map-support-browser.js")
stack = File.binread("#{__dir__}/source-map-support-browser.js")

ext = builder.output_extension
module_type = ' type="module"' if builder.esm?

# Chrome can't handle huge data passed to `addScriptToEvaluateOnLoad`
# https://groups.google.com/a/chromium.org/forum/#!topic/chromium-discuss/U5qyeX_ydBo
# The only way is to create temporary files and pass them to chrome.
File.write("#{dir}/index.#{ext}", js)
File.write("#{dir}/source-map-support.js", stack)
File.write("#{dir}/index.html", <<~HTML)
File.binwrite("#{dir}/index.#{ext}", js)
File.binwrite("#{dir}/source-map-support.js", stack)
File.binwrite("#{dir}/index.html", <<~HTML)
<html><head>
<meta charset='utf-8'>
<script src='./source-map-support.js'></script>
Expand Down Expand Up @@ -124,7 +124,7 @@ def run_chrome_server

chrome_pid = Process.spawn(chrome_server_cmd)

Timeout.timeout(10) do
Timeout.timeout(30) do
loop do
break if chrome_server_running?
sleep 0.5
Expand All @@ -137,7 +137,7 @@ def run_chrome_server
puts 'Make sure that you have it installed and that its version is > 59'
exit(1)
ensure
if windows? && chrome_pid
if OS.windows? && chrome_pid
Process.kill('KILL', chrome_pid) unless system("taskkill /f /t /pid #{chrome_pid} >NUL 2>NUL")
elsif chrome_pid
Process.kill('HUP', chrome_pid)
Expand Down
4 changes: 2 additions & 2 deletions lib/opal/cli_runners/system_runner.rb
Expand Up @@ -27,9 +27,9 @@

tempfile =
if debug
File.new("opal-nodejs-runner.#{ext}", 'w')
File.new("opal-nodejs-runner.#{ext}", 'wb')
else
Tempfile.new(['opal-system-runner', ".#{ext}"])
Tempfile.new(['opal-system-runner', ".#{ext}"], mode: File::BINARY)
end

tempfile.write code
Expand Down
7 changes: 5 additions & 2 deletions lib/opal/eof_content.rb
Expand Up @@ -15,9 +15,12 @@ def eof
eof_content = @source[last_token_position..-1]
return nil unless eof_content

eof_content = eof_content.lines.drop_while { |line| line == "\n" }
# On Windows token position is off a bit, because Parser does not seem to compensate for \r\n
# The first eof_content line on Windows may be for example "end\r\n"
# Must match for it and \r\n and \n
eof_content = eof_content.lines.drop_while { |line| /\A.*\r?\n?\z/.match?(line) && !line.start_with?('__END__') }

if eof_content[0] == "__END__\n"
if /\A__END__\r?\n?\z/.match?(eof_content[0])
eof_content = eof_content[1..-1] || []
eof_content.join
elsif eof_content == ['__END__']
Expand Down
5 changes: 3 additions & 2 deletions lib/opal/source_map/file.rb
Expand Up @@ -182,8 +182,9 @@ def absolute_mappings
def fragments_by_line
raw_mappings = [[]]
fragments.flat_map do |fragment|
fragment_code = fragment.code
fragment_lines = fragment_code.split("\n", -1) # a negative limit won't suppress trailing null values
fragment_code = fragment.code
splitter = /\r/.match?(fragment_code) ? /\r?\n/ : "\n"
fragment_lines = fragment_code.split(splitter, -1) # a negative limit won't suppress trailing null values
fragment_lines.each.with_index do |fragment_line, index|
raw_segment = [fragment_line, fragment]
if index.zero? && !fragment_line.size.zero?
Expand Down
9 changes: 9 additions & 0 deletions spec/opal/core/language/DATA/characters_support_crlf_spec.rb
@@ -0,0 +1,9 @@
describe "characters support of the DATA contstant" do
it "supports all characters" do
DATA.read.should == "azAZ09`~!@#$%^&*(\r\n)_+{}\\|;:'\",<.>/?\r\n"
end
end

__END__
azAZ09`~!@#$%^&*(
)_+{}\|;:'",<.>/?
10 changes: 10 additions & 0 deletions spec/opal/core/language/DATA/multiple___END___crlf_spec.rb
@@ -0,0 +1,10 @@
describe "DATA constant with multiple __END__ sections" do
it "returns everything after first __END__" do
DATA.read.should == "1\r\n__END__\r\n2\r\n"
end
end

__END__
1
__END__
2
5 changes: 3 additions & 2 deletions test/nodejs/test_file.rb
Expand Up @@ -175,6 +175,7 @@ def test_windows_separators
end if windows_platform?

def test_windows_file_expand_path
# do not use d: because its a symlink in github actions fs, leading to unexpected results
drive_letter = Dir.pwd.slice(0, 2)
assert_equal(Dir.pwd + '/foo/bar.js', File.expand_path('./foo/bar.js'))
assert_equal(drive_letter + '/foo/bar.js', File.expand_path('/foo/bar.js'))
Expand All @@ -186,8 +187,8 @@ def test_windows_file_expand_path
assert_equal('c:/bar.js', File.expand_path('\\..\\bar.js', 'c:\\foo\\baz\\'))
assert_equal('c:/foo/baz/bar.js', File.expand_path('baz\\bar.js', 'c:\\foo'))
assert_equal('c:/baz/bar.js', File.expand_path('baz\\bar.js', 'c:\\foo\\..'))
assert_equal('d:/', File.expand_path('d:'), 'should add a trailing slash when the path is d:')
assert_equal('d:/', File.expand_path('d:/'), 'should preserve the trailing slash when the path d:/')
assert_equal('f:/', File.expand_path('f:'), 'should add a trailing slash when the path is d:')
assert_equal('g:/', File.expand_path('g:/'), 'should preserve the trailing slash when the path d:/')
assert_equal(Dir.pwd, File.expand_path(drive_letter), 'should expand to the current directory when the path is c: (and the current directory is located in the c drive)')
assert_equal(drive_letter + '/', drive_letter + '/', 'should return c:/ when the path is c:/ because the path is absolute')
end if windows_platform?
Expand Down

0 comments on commit 076bf7e

Please sign in to comment.