Skip to content

Commit

Permalink
ci fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
neenjaw committed Apr 10, 2021
1 parent ca72644 commit e143b4e
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 102 deletions.
34 changes: 19 additions & 15 deletions bin/dialyzer_check.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
#!/bin/bash

# currently dialyzer is timing out after 30 mins only on elixir 1.7 / otp 19
if elixir --version | grep -q 'Elixir 1.7'; then
echo "skipping dialyzer for Elixir 1.7"
exit 0
fi

mkdir -p ./priv/plts

mkdir -p ./tmp/src
mkdir ./tmp/build

for example_file in exercises/concept/**/mix.exs
for example_file in $(find ./exercises -type f -name '*mix.exs')
do
exercise_dir=$(dirname $example_file)
exercise=$(basename $exercise_dir)
cp "${exercise_dir}/.meta/exemplar.ex" "./tmp/src/${exercise}.ex"
done

for example_file in exercises/practice/**/mix.exs
do
exercise_dir=$(dirname "${example_file}")
exercise=$(basename "${exercise_dir}")
cp "${exercise_dir}/.meta/example.ex" "./tmp/src/${exercise}.ex"
# concept exercises have "exemplar" solutions
if [ -f "${exercise_dir}/.meta/exemplar.ex" ]; then
cp "${exercise_dir}/.meta/exemplar.ex" "./tmp/src/${exercise}.ex"
fi

# practice exercises have "example" solutions
if [ -f "${exercise_dir}/.meta/example.ex" ]; then
cp "${exercise_dir}/.meta/example.ex" "./tmp/src/${exercise}.ex"
fi

support_files=($(jq -r '(.files.editor[])?' "${exercise_dir}/.meta/config.json"))
for support_file_path in "${support_files[@]}"
do
file=$(basename "${support_file_path}")
cp "${exercise_dir}/${support_file_path}" "./tmp/src/${file}"
done
done

elixirc -o ./_build ./tmp/src/*.ex
mix dialyzer --no-check
mix deps.get
mix dialyzer
RESULT=$?
rm -rf ./tmp

Expand Down
35 changes: 19 additions & 16 deletions bin/test_exercises.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#!/usr/bin/env bash

set -euo pipefail

# ###
# test_exercises.sh, by Tim Austin (neenjaw) [email protected]
# ###
# Script is to test each exercise against it's test unit individually
# against the example solution to prove the test works, and the problem
Expand Down Expand Up @@ -42,17 +42,20 @@ cp -a exercises tmp-exercises
# test each exercise
for exercise in tmp-exercises/*/*
do
if [ -d $exercise ]
if [ -d ${exercise} ]
then
cd "$exercise"
cd "${exercise}"

exercise_name=$(basename $exercise)
test_count=$((test_count+1))

printf "\\033[33mTesting\\033[0m: $exercise_name "

exercise_config=".meta/config.json"
files_to_remove=($(jq -r '.files.solution[]' "${exercise_config}"))

# Move the example into the lib file
for file in lib/*
for file in "${files_to_remove[@]}"
do
rm -r "$file"
done
Expand All @@ -71,15 +74,15 @@ do
compiler_results=$(MIX_ENV=test mix compile --force --warnings-as-errors 2>&1)
compile_exit_code="$?"

if [ "$compile_exit_code" -eq 0 ]
if [ "${compile_exit_code}" -eq 0 ]
then
# turn on doctests
test_file=`find . -name \*_test.exs`
module_name=`cat $test_file | sed -rn 's/^defmodule (.*)Test do$/\1 /p'`
test_file=$(find . -name \*_test.exs)
module_name=$(cat "${test_file}" | sed -rn 's/^defmodule (.*)Test do$/\1 /p')
doctest_code="doctest ${module_name}"

# Warning: GNU sed necessary, BSD (macOS) sed has incompatible options
sed -i 's/use ExUnit.Case\(.*\)/use ExUnit.Case\1\n'" ${doctest_code}"'\n/g' $test_file
sed -i 's/use ExUnit.Case\(.*\)/use ExUnit.Case\1\n'" ${doctest_code}"'\n/g' "${test_file}"

# perform unit tests
test_results=$(mix test --color --no-elixir-version-check --include pending 2> /dev/null)
Expand All @@ -90,19 +93,19 @@ do
fi

# based on compiler and unit test, print results
if [ "$compile_exit_code" -eq 0 -a "$test_exit_code" -eq 0 ]
if [ "${compile_exit_code}" -eq 0 -a "${test_exit_code}" -eq 0 ]
then
printf "\\033[32mPass\\033[0m\n"
pass_count=$((pass_count+1))
else
printf "\\033[31mFail\\033[0m\n"

if [ "$compile_exit_code" -ne 0 ]
if [ "${compile_exit_code}" -ne 0 ]
then
printf "\\033[36mcompiler output\\033[0m "; printf -- '-%.0s' {1..61}; echo ""
printf "${compiler_results}\n"
fi
if [ "$test_exit_code" -ne 0 -a "$test_exit_code" -ne 5 ]
if [ "${test_exit_code}" -ne 0 -a "${test_exit_code}" -ne 5 ]
then
printf "\\033[36mtest output\\033[0m "; printf -- '-%.0s' {1..65}; echo ""
printf "${test_results}\n"
Expand All @@ -113,7 +116,7 @@ do
failing_exercises+=( $exercise_name )
fi

cd "$relative_root"
cd "${relative_root}"
fi
done

Expand All @@ -124,13 +127,13 @@ rm -rf tmp-exercises
printf -- '-%.0s' {1..80}; echo ""
printf "${pass_count}/${test_count} tests passed.\n"

if [ "$fail_count" -eq 0 ]
if [ "${fail_count}" -eq 0 ]
then
# everything is good, exit
exit 0;
else
# There was at least one problem, list the exercises with problems.
printf "${fail_count} $(test_or_tests "$fail_count") failing:\n"
printf "${fail_count} $(test_or_tests "${fail_count}") failing:\n"

for exercise in ${failing_exercises[@]}
do
Expand Down
10 changes: 4 additions & 6 deletions exercises/practice/dot-dsl/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Instructions

A [Domain Specific Language
(DSL)](https://en.wikipedia.org/wiki/Domain-specific_language) is a
A [Domain Specific Language (DSL)](https://en.wikipedia.org/wiki/Domain-specific_language) is a
small language optimized for a specific domain. Since a DSL is
targeted, it can greatly impact productivity/understanding by allowing the
writer to declare *what* they want rather than *how*.
writer to declare _what_ they want rather than _how_.

One problem area where they are applied are complex customizations/configurations.

For example the [DOT language](https://en.wikipedia.org/wiki/DOT_(graph_description_language)) allows
For example the [DOT language](<https://en.wikipedia.org/wiki/DOT_(graph_description_language)>) allows
you to write a textual description of a graph which is then transformed into a picture by one of
the [Graphviz](http://graphviz.org/) tools (such as `dot`). A simple graph looks like this:

Expand All @@ -19,8 +18,7 @@ the [Graphviz](http://graphviz.org/) tools (such as `dot`). A simple graph looks
a -- b [color="green"]
}

Putting this in a file `example.dot` and running `dot example.dot -T png
-o example.png` creates an image `example.png` with red and blue circle
Putting this in a file `example.dot` and running `dot example.dot -T png -o example.png` creates an image `example.png` with red and blue circle
connected by a green line on a yellow background.

Write a Domain Specific Language similar to the Graphviz dot language using the provided `Graph` data structure.
Expand Down
17 changes: 6 additions & 11 deletions exercises/practice/dot-dsl/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@
"rubysolo",
"sotojuan",
"Teapane",
"waiting-for-dev"
"waiting-for-dev",
"marcandre"
],
"files": {
"solution": [
"lib/dot.ex",
"lib/graph.ex"
],
"test": [
"test/dot_test.exs"
],
"example": [
".meta/example.ex"
]
"solution": ["lib/dot.ex"],
"test": ["test/dot_test.exs"],
"editor": ["lib/graph.ex"],
"example": [".meta/example.ex"]
},
"source": "Wikipedia",
"source_url": "https://en.wikipedia.org/wiki/DOT_(graph_description_language)"
Expand Down
14 changes: 4 additions & 10 deletions exercises/practice/zipper/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@
"waiting-for-dev"
],
"files": {
"solution": [
"lib/zipper.ex",
"lib/bin_tree.ex"
],
"test": [
"test/zipper_test.exs"
],
"example": [
".meta/example.ex"
]
"solution": ["lib/zipper.ex"],
"test": ["test/zipper_test.exs"],
"editor": ["lib/bin_tree.ex"],
"example": [".meta/example.ex"]
}
}
53 changes: 9 additions & 44 deletions exercises/practice/zipper/.meta/example.ex
Original file line number Diff line number Diff line change
@@ -1,38 +1,4 @@
defmodule BinTree do
@moduledoc """
A node in a binary tree.
`value` is the value of a node.
`left` is the left subtree (nil if no subtree).
`right` is the right subtree (nil if no subtree).
"""

@type t :: %BinTree{value: any, left: t() | nil, right: t() | nil}

defstruct [:value, :left, :right]
end

defimpl Inspect, for: BinTree do
import Inspect.Algebra

# A custom inspect instance purely for the tests, this makes error messages
# much more readable.
#
# %BinTree{value: 3, left: %BinTree{value: 5, right: %BinTree{value: 6}}} becomes (3:(5::(6::)):)
def inspect(%BinTree{value: value, left: left, right: right}, opts) do
concat([
"(",
to_doc(value, opts),
":",
if(left, do: to_doc(left, opts), else: ""),
":",
if(right, do: to_doc(right, opts), else: ""),
")"
])
end
end

defmodule BinTree.Zipper do
defmodule Zipper do
@moduledoc """
A binary tree zipper.
Expand All @@ -44,18 +10,17 @@ defmodule BinTree.Zipper do
The trail stores the path that a zipper has taken into the tree from the root
and the alternative branches.
"""
@type t :: %BinTree.Zipper{

alias BinTree, as: BT
alias __MODULE__, as: Z

@type t :: %Z{
value: any,
left: BinTree.Zipper.t() | nil,
right: BinTree.Zipper.t() | nil,
trail: [{:left, any, BinTree.t()} | {:right, any, BinTree.t()}]
left: BT.t() | nil,
right: BT.t() | nil,
trail: [{:left, any, BT.t()} | {:right, any, BT.t()}]
}
defstruct value: nil, left: nil, right: nil, trail: []
end

defmodule Zipper do
alias BinTree, as: BT
alias BinTree.Zipper, as: Z

@doc """
Get a zipper focussed on the root node.
Expand Down

0 comments on commit e143b4e

Please sign in to comment.