Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Elixir CI - Linux

on: push

jobs:
ubuntu:
runs-on: ubuntu-24.04
name: Linux OTP ${{matrix.pair.otp-version}} / Elixir ${{matrix.pair.elixir-version}}
strategy:
matrix:
pair:
- otp-version: '27.3'
elixir-version: '1.18.3'
- otp-version: '27.3'
elixir-version: '1.17.3'
- otp-version: '26.2'
elixir-version: '1.16.3'
- otp-version: '25.3'
elixir-version: '1.15.8'
- otp-version: '24.3'
elixir-version: '1.14.5'
steps:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.pair.otp-version}}
elixir-version: ${{matrix.pair.elixir-version}}

- uses: actions/cache@v3
id: deps-cache
with:
path: deps
key: ${{ runner.os }}-mix-${{ matrix.pair.otp-version }}-${{ matrix.pair.elixir-version }}-${{ hashFiles('/mix.lock') }}-${{ hashfiles('installer/**/*') }}

- name: Install dependencies
run: mix deps.get

- uses: actions/cache@v3
id: build-cache
with:
path: _build
key: ${{ runner.os }}-build-${{ matrix.pair.otp-version }}-${{ matrix.elixir-version }}-${{ hashFiles('/mix.lock') }}

- name: Compile base
run: mix compile

- uses: actions/cache@v3
id: zig-cache
with:
path: test/_support/zig-0.14.0
key: ${{ runner.os }}-zig-${{ steps.zig-version.outputs.stdout }}

- name: Run Tests
env:
RUNNING_CI: "TRUE"
ZIGLER_TEST_BLAS: "TRUE"
run: mix test --exclude no_ci
40 changes: 40 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Elixir CI - Windows

on: push

jobs:
test:
runs-on: windows-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: '1.18.3' # adjust as needed
otp-version: '27.3' # adjust as needed

- uses: actions/cache@v3
id: deps-cache
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('/mix.lock') }}-${{ hashfiles('/installer/**/*') }}

- name: Install dependencies
run: mix deps.get

- uses: actions/cache@v3
id: build-cache
with:
path: _build
key: ${{ runner.os }}-build-${{ hashFiles('/mix.lock') }}

- name: Compile base
run: mix compile

- name: Run Tests
env:
RUNNING_CI: "TRUE"
run: mix test
5 changes: 4 additions & 1 deletion lib/zig.parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ defmodule Zig.Parser do
end

def parse(string) do
case parser(string) do
string
|> String.replace("\r\n", "\n")
|> parser
|> case do
{:ok, _, "", parser, _, _} ->
%{
parser
Expand Down
33 changes: 31 additions & 2 deletions test/_support/zig_tree.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,42 @@ defmodule ZigParserTest.ZigTree do
end
end

@otp_version :otp_release
|> :erlang.system_info()
|> List.to_integer()

if @otp_version >= 25 do
defp ssl_opts do
[
verify: :verify_peer,
cacerts: :public_key.cacerts_get()
]
end
else
defp ssl_opts do
# unfortunately in otp 24 there is not a clean way of obtaining cacerts
[]
end
end

defp download_zig_zipfile do
{:ok, _} = Application.ensure_all_started(:ssl)
{:ok, _} = Application.ensure_all_started(:inets)

headers = []
request = {~C'https://ziglang.org/builds/zig-0.14.0.tar.xz', headers}
http_options = [timeout: 600_000]
request = {~C'https://ziglang.org/download/0.14.0/zig-0.14.0.tar.xz', headers}

http_options = [
timeout: 600_000,
ssl:
[
depth: 100,
customize_hostname_check: [
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
]
] ++ ssl_opts()
]

options = [body_format: :binary]

case :httpc.request(:get, request, http_options, options) do
Expand Down
101 changes: 52 additions & 49 deletions test/everything_test.exs
Original file line number Diff line number Diff line change
@@ -1,63 +1,66 @@
defmodule ZigParserTest.EverythingHelper do
@rejected MapSet.new(~w[
if match?({:unix, _}, :os.type()) do
defmodule ZigParserTest.EverythingHelper do
@rejected MapSet.new(~w[
# PARSE TOO SLOW:
test/_support/zig-0.14.0/src/arch/x86_64/CodeGen.zig
test/_support/zig-0.14.0/lib/compiler_rt/udivmodti4_test.zig
])

def dir_walk("test/_support/zig-0.14.0/test/cases/compile_errors" <> _), do: []
def dir_walk("test/_support/zig-0.14.0/test/cases/compile_errors" <> _), do: []

def dir_walk(dir) do
{dirs, files} =
dir
|> File.ls!()
|> Enum.map(&Path.join(dir, &1))
|> Enum.split_with(&File.dir?/1)
def dir_walk(dir) do
{dirs, files} =
dir
|> File.ls!()
|> Enum.map(&Path.join(dir, &1))
|> Enum.split_with(&File.dir?/1)

zig_files =
files
|> Enum.filter(&(Path.extname(&1) == ".zig"))
|> Enum.reject(&(&1 in @rejected))
zig_files =
files
|> Enum.filter(&(Path.extname(&1) == ".zig"))
|> Enum.reject(&(&1 in @rejected))

[zig_files | Enum.flat_map(dirs, &dir_walk(&1))]
[zig_files | Enum.flat_map(dirs, &dir_walk(&1))]
end
end
end

alias ZigParserTest.EverythingHelper

parent_dir = "test/_support/zig-0.14.0"
subdirs = ~W[lib src test]

subdirs
|> Stream.map(&Path.join(parent_dir, &1))
|> Stream.flat_map(&EverythingHelper.dir_walk/1)
|> Stream.reject(&(&1 == []))
|> Enum.each(fn [first | _] = files ->
dir = Path.dirname(first)

mod =
dir
|> String.replace_leading(parent_dir <> "/", "")
|> Macro.camelize()
|> String.replace_prefix("", "Elixir.")
|> String.to_atom()

code =
quote bind_quoted: binding() do
defmodule mod do
use ExUnit.Case, async: true
@moduletag :everything

describe dir do
for file <- files do
test file do
unquote(file)
|> File.read!()
|> Zig.Parser.parse()
alias ZigParserTest.EverythingHelper

parent_dir = "test/_support/zig-0.14.0"
subdirs = ~W[lib src test]

subdirs
|> Stream.map(&Path.join(parent_dir, &1))
|> Stream.flat_map(&EverythingHelper.dir_walk/1)
|> Stream.reject(&(&1 == []))
|> Enum.each(fn [first | _] = files ->
dir = Path.dirname(first)

mod =
dir
|> String.replace_leading(parent_dir <> "/", "")
|> Macro.camelize()
|> String.replace_prefix("", "Elixir.")
|> String.to_atom()

code =
quote bind_quoted: binding() do
defmodule mod do
use ExUnit.Case, async: true
@moduletag :everything

describe dir do
for file <- files do
test file do
unquote(file)
|> File.read!()
|> Zig.Parser.parse()
end
end
end
end
end
end

Code.eval_quoted(code)
end)
Code.eval_quoted(code)
end)
end
22 changes: 12 additions & 10 deletions test/parser/switch_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,21 @@ defmodule Zig.Parser.Test.SwitchTest do
end

test "labelled continue" do
assert [%{value: %Switch{prongs: [{[integer: 1], {:continue, :s, _}}], label: :s}}] = Parser.parse("""
const result = s: switch (@as(u32, 1)) {
1 => continue :s 123,
};
""").code
assert [%{value: %Switch{prongs: [{[integer: 1], {:continue, :s, _}}], label: :s}}] =
Parser.parse("""
const result = s: switch (@as(u32, 1)) {
1 => continue :s 123,
};
""").code
end

test "labelled switch that is a loop." do
assert [%{block: %{code: [%Switch{label: :eval}]}}] = Parser.parse("""
fn doTheTest() !void {
eval: switch (val) {}
}
""").code
assert [%{block: %{code: [%Switch{label: :eval}]}}] =
Parser.parse("""
fn doTheTest() !void {
eval: switch (val) {}
}
""").code
end
end
end
4 changes: 3 additions & 1 deletion test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ZigParserTest.ZigTree.ensure_zig_directory()
if match?({:unix, _}, :os.type()) do
ZigParserTest.ZigTree.ensure_zig_directory()
end

ExUnit.start()
Loading