Skip to content

Commit

Permalink
Merge branch 'master' into changelog/1.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored Jul 8, 2024
2 parents e2ba43c + 0571f19 commit 066db43
Show file tree
Hide file tree
Showing 167 changed files with 1,915 additions and 756 deletions.
10 changes: 2 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ parameters:
distribution-scripts-version:
description: "Git ref for version of https://github.com/crystal-lang/distribution-scripts/"
type: string
default: "7a013f14ed64e7e569b5e453eab02af63cf62b61"
default: "96e431e170979125018bd4fd90111a3147477eec"
previous_crystal_base_url:
description: "Prefix for URLs to Crystal bootstrap compiler"
type: string
Expand Down Expand Up @@ -296,12 +296,7 @@ jobs:
command: |
brew unlink python@2 || true
# We need ruby-install >= 0.8.3
brew install ruby-install
ruby-install ruby 2.7.3
brew install pkgconfig libtool
brew install ruby@3 libffi pkgconfig libtool automake
sudo mkdir -p /opt/crystal
sudo chown $(whoami) /opt/crystal/
Expand All @@ -312,7 +307,6 @@ jobs:
- run:
no_output_timeout: 40m
command: |
echo "2.7.3" > /tmp/workspace/distribution-scripts/.ruby-version
cd /tmp/workspace/distribution-scripts
source build.env
cd omnibus
Expand Down
7 changes: 4 additions & 3 deletions scripts/github-changelog.cr
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,10 @@ record PullRequest,

topics.sort_by! { |parts|
topic_priority = case parts[0]
when "tools" then 2
when "lang" then 1
else 0
when "infrastructure" then 3
when "tools" then 2
when "lang" then 1
else 0
end
{-topic_priority, parts[0]}
}
Expand Down
6 changes: 3 additions & 3 deletions spec/compiler/crystal/tools/format_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe Crystal::Command::FormatCommand do
format_command.run
format_command.status_code.should eq(1)
stdout.to_s.should be_empty
stderr.to_s.should contain("file 'STDIN' is not a valid Crystal source file: Unexpected byte 0xff at position 1, malformed UTF-8")
stderr.to_s.should contain("file 'STDIN' is not a valid Crystal source file: Unexpected byte 0xfe at position 0, malformed UTF-8")
end

it "formats stdin (bug)" do
Expand Down Expand Up @@ -162,7 +162,7 @@ describe Crystal::Command::FormatCommand do
format_command.status_code.should eq(1)
stdout.to_s.should contain("Format #{Path[".", "format.cr"]}")
stderr.to_s.should contain("syntax error in '#{Path[".", "syntax_error.cr"]}:1:3': unexpected token: EOF")
stderr.to_s.should contain("file '#{Path[".", "invalid_byte_sequence_error.cr"]}' is not a valid Crystal source file: Unexpected byte 0xff at position 1, malformed UTF-8")
stderr.to_s.should contain("file '#{Path[".", "invalid_byte_sequence_error.cr"]}' is not a valid Crystal source file: Unexpected byte 0xfe at position 0, malformed UTF-8")

File.read(File.join(path, "format.cr")).should eq("if true\n 1\nend\n")
end
Expand Down Expand Up @@ -226,7 +226,7 @@ describe Crystal::Command::FormatCommand do
stderr.to_s.should_not contain("not_format.cr")
stderr.to_s.should contain("formatting '#{Path[".", "format.cr"]}' produced changes")
stderr.to_s.should contain("syntax error in '#{Path[".", "syntax_error.cr"]}:1:3': unexpected token: EOF")
stderr.to_s.should contain("file '#{Path[".", "invalid_byte_sequence_error.cr"]}' is not a valid Crystal source file: Unexpected byte 0xff at position 1, malformed UTF-8")
stderr.to_s.should contain("file '#{Path[".", "invalid_byte_sequence_error.cr"]}' is not a valid Crystal source file: Unexpected byte 0xfe at position 0, malformed UTF-8")
end
end
end
Expand Down
85 changes: 80 additions & 5 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "spec"
require "../../../src/compiler/crystal/formatter"

private def assert_format(input, output = input, strict = false, flags = nil, file = __FILE__, line = __LINE__)
it "formats #{input.inspect}", file, line do
private def assert_format(input, output = input, strict = false, flags = nil, file = __FILE__, line = __LINE__, focus = false)
it "formats #{input.inspect}", file, line, focus: focus do
output = "#{output}\n" unless strict
result = Crystal.format(input, flags: flags)
unless result == output
Expand Down Expand Up @@ -812,7 +812,7 @@ describe Crystal::Formatter do
end
CRYSTAL
def foo(x,
y)
y,)
yield
end
CRYSTAL
Expand Down Expand Up @@ -888,7 +888,7 @@ describe Crystal::Formatter do
end
CRYSTAL
def foo(
x
x,
)
yield
end
Expand All @@ -901,6 +901,39 @@ describe Crystal::Formatter do
CRYSTAL
end

# Allows trailing commas, but doesn't enforce them
assert_format <<-CRYSTAL
def foo(
a,
b
)
end
CRYSTAL

assert_format <<-CRYSTAL
def foo(
a,
b,
)
end
CRYSTAL

assert_format <<-CRYSTAL
macro foo(
a,
*b,
)
end
CRYSTAL

assert_format <<-CRYSTAL
macro foo(
a,
**b,
)
end
CRYSTAL

context "adds trailing comma to def multi-line normal, splat, and double splat parameters" do
assert_format <<-CRYSTAL, <<-CRYSTAL, flags: %w[def_trailing_comma]
macro foo(
Expand Down Expand Up @@ -1120,6 +1153,41 @@ describe Crystal::Formatter do
)
end
CRYSTAL

assert_format <<-CRYSTAL, flags: %w[def_trailing_comma]
def foo(a)
end
CRYSTAL

assert_format <<-CRYSTAL, flags: %w[def_trailing_comma]
def foo(a, b)
end
CRYSTAL

assert_format <<-CRYSTAL, flags: %w[def_trailing_comma]
def foo(a, *args)
end
CRYSTAL

assert_format <<-CRYSTAL, flags: %w[def_trailing_comma]
def foo(a, *args, &block)
end
CRYSTAL

assert_format <<-CRYSTAL, flags: %w[def_trailing_comma]
def foo(a, **kwargs)
end
CRYSTAL

assert_format <<-CRYSTAL, flags: %w[def_trailing_comma]
def foo(a, **kwargs, &block)
end
CRYSTAL

assert_format <<-CRYSTAL, flags: %w[def_trailing_comma]
def foo(a, &block)
end
CRYSTAL
end

assert_format "1 + 2", "1 + 2"
Expand Down Expand Up @@ -1658,6 +1726,13 @@ describe Crystal::Formatter do
assert_format "-> : Int32 {}", "-> : Int32 { }", flags: %w[proc_literal_whitespace]
assert_format "->do\nend", "-> do\nend", flags: %w[proc_literal_whitespace]

# Allows whitespace around proc literal, but doesn't enforce them
assert_format "-> { }"
assert_format "-> { 1 }"
assert_format "->(x : Int32) { }"
assert_format "-> : Int32 { }"
assert_format "-> do\nend"

assert_format "-> : Int32 {}"
assert_format "-> : Int32 | String { 1 }"
assert_format "-> : Array(Int32) {}"
Expand All @@ -1668,7 +1743,7 @@ describe Crystal::Formatter do
assert_format "-> : {Int32} { String }"
assert_format "-> : {x: Int32, y: String} {}"
assert_format "->\n:\nInt32\n{\n}", "-> : Int32 {\n}"
assert_format "->( x )\n:\nInt32 { }", "->(x) : Int32 {}"
assert_format "->( x )\n:\nInt32 { }", "->(x) : Int32 { }"
assert_format "->: Int32 do\nx\nend", "-> : Int32 do\n x\nend"

{:+, :-, :*, :/, :^, :>>, :<<, :|, :&, :&+, :&-, :&*, :&**}.each do |sym|
Expand Down
9 changes: 9 additions & 0 deletions spec/compiler/lexer/lexer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,15 @@ describe "Lexer" do
assert_syntax_error "'\\u{DFFF}'", "invalid unicode codepoint (surrogate half)"
assert_syntax_error ":+1", "unexpected token"

it "invalid byte sequence" do
expect_raises(InvalidByteSequenceError, "Unexpected byte 0xff at position 0, malformed UTF-8") do
parse "\xFF"
end
expect_raises(InvalidByteSequenceError, "Unexpected byte 0xff at position 1, malformed UTF-8") do
parse " \xFF"
end
end

assert_syntax_error "'\\1'", "invalid char escape sequence"

it_lexes_string %("\\1"), String.new(Bytes[1])
Expand Down
5 changes: 5 additions & 0 deletions spec/compiler/macro/macro_methods_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,11 @@ module Crystal
assert_macro %({{"hello world".titleize}}), %("Hello World")
end

it "executes to_utf16" do
assert_macro %({{"hello".to_utf16}}), "(::Slice(::UInt16).literal(104_u16, 101_u16, 108_u16, 108_u16, 111_u16, 0_u16))[0, 5]"
assert_macro %({{"TEST 😐🐙 ±∀ の".to_utf16}}), "(::Slice(::UInt16).literal(84_u16, 69_u16, 83_u16, 84_u16, 32_u16, 55357_u16, 56848_u16, 55357_u16, 56345_u16, 32_u16, 177_u16, 8704_u16, 32_u16, 12398_u16, 0_u16))[0, 14]"
end

it "executes to_i" do
assert_macro %({{"1234".to_i}}), %(1234)
end
Expand Down
25 changes: 25 additions & 0 deletions spec/primitives/pointer_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "spec"
require "../support/finalize"
require "../support/interpreted"

private class Inner
include FinalizeCounter

def initialize(@key : String)
end
end

private class Outer
@inner = Inner.new("reference-storage")
end

describe "Primitives: pointer" do
describe ".malloc" do
pending_interpreted "is non-atomic for ReferenceStorage(T) if T is non-atomic (#14692)" do
FinalizeState.reset
outer = Outer.unsafe_construct(Pointer(ReferenceStorage(Outer)).malloc(1))
GC.collect
FinalizeState.count("reference-storage").should eq(0)
end
end
end
Loading

0 comments on commit 066db43

Please sign in to comment.