Skip to content

Commit

Permalink
🛠 Use CMake and Python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo Weidmann committed Feb 5, 2017
1 parent 927d4d5 commit dd0f8ed
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 148 deletions.
5 changes: 3 additions & 2 deletions .gitignore
@@ -1,6 +1,5 @@
# Emojicode
builds
*.o
build

# Xcode
#
Expand Down Expand Up @@ -53,3 +52,5 @@ Icon
Network Trash Folder
Temporary Items
.apdisk

__pycache__
10 changes: 6 additions & 4 deletions .travis.yml
Expand Up @@ -3,17 +3,19 @@ compiler:
- gcc
- clang
sudo: required
script: make && make tests
script: mkdir build && cd build && cmake .. -GNinja && ninja && ninja tests
dist: trusty
install:
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.9" CC="gcc-4.9"; fi
- if [ "$CXX" = "g++" ]; then export CXX="g++-5" CC="gcc-5"; fi
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.9
- g++-4.9
- ninja-build
- python3
- gcc-5
- g++-5
- liballegro5-dev
- liballegro-acodec5-dev
- liballegro-audio5-dev
Expand Down
25 changes: 25 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.2.2)
project(Emojicode)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_STANDARD 11)

if(heapSize)
add_definitions(-DheapSize=${heapSize})
endif()

if(defaultPackagesDirectory)
add_definitions(-DdefaultPackagesDirectory=${defaultPackagesDirectory})
endif()

file(GLOB EMOJICODE_SOURCES "EmojicodeReal-TimeEngine/*")
add_executable(emojicode ${EMOJICODE_SOURCES} utf8.c utf8.h)
target_compile_options(emojicode PUBLIC -Ofast -Wall -Wno-unused-result -Wno-missing-braces -pedantic)
target_link_libraries(emojicode dl pthread)

file(GLOB EMOJICODEC_SOURCES "EmojicodeCompiler/*")
add_executable(emojicodec ${EMOJICODEC_SOURCES} utf8.c utf8.h)
target_compile_options(emojicodec PUBLIC -Ofast -Wall -Wno-unused-result -Wno-missing-braces -pedantic)

add_custom_target(dist python3 ${PROJECT_SOURCE_DIR}/dist.py ${PROJECT_SOURCE_DIR})
add_custom_target(tests python3 ${PROJECT_SOURCE_DIR}/tests.py ${PROJECT_SOURCE_DIR} DEPENDS dist)
119 changes: 0 additions & 119 deletions Makefile

This file was deleted.

49 changes: 26 additions & 23 deletions README.md
Expand Up @@ -19,62 +19,65 @@ Follow Emojicode’s Twitter account

## 🔨 Building from source

If you need to build Emojicode from source you can of course also do this. **We, however, recommend you to install Emojicode from the prebuilt binaries if possible.**
If you don’t want to use the prebuilt binaries, you can of course also build
Emojicode from source.

**These build instructions only apply to the latest code in the master branch.
To build previous versions, please consult the according README.md by cloning
the repository and checking out a version: `git checkout v0.3`**

Prerequisites:

- clang and clang++ 3.4 or newer, or
- gcc and g++ 4.9 or newer
- GNU Make
- CMake 3.5.1 and (preferably) Ninja
- Python 3.5.2 or above to pack for distribution and run tests
- Allegro 5 to compile the allegro package
- `sudo apt-get install liballegro5-dev` on Debian/Ubuntu
- `brew install allegro` on OS X

Steps:

1. Clone Emojicode (or download the source code and extract it) and navigate into it:
1. Clone Emojicode (or download the source code and extract it) and navigate
into it:

```
git clone https://github.com/emojicode/emojicode
cd emojicode
```

Beware of, that the master branch contains development code which probably contains bugs. If you want to build the latest stable release make sure to check it out first: `git checkout v0.3`

2. Then simply run
2. Create a `build` directory and run CMake in it:

```
make
mkdir build
cd build
cmake .. -GNinja
```

to compile the Engine, the compiler and all default packages.

You may need to use a smaller heap size on older Raspberry Pis, for example.
You can specify the heap size in bytes when compiling the engine:
You can specify the heap size in bytes, which defaults to 512MB, with
`-DheapSize` and the default package search path with
`-DdefaultPackagesDirectory` like so:

```
make HEAP_SIZE=128000000
cmake -DheapSize=128000000 -DdefaultPackagesDirectory=/opt/strange/place .. -GNinja
```

The default heap size is 512MB. It’s also possible to change the default
package search path by setting `DEFAULT_PACKAGES_DIRECTORY`. As for example:

```
make DEFAULT_PACKAGES_DIRECTORY=/opt/strange/place
```
You can of course also run CMake in another directory or use another build
system than Ninja. Refer to the CMake documentation for more information.

3. Run the tests:
3. Build the Compiler and Real-Time Engine:

```
make tests
ninja
```

4. You can now either install Emojicode:
4. You can now test Emojicode:

```
make install
ninja tests
```

or copy the binaries from `builds/`.
and take the distribution package created inside the build directory.

## 📝 Contributions

Expand Down
36 changes: 36 additions & 0 deletions dist.py
@@ -0,0 +1,36 @@
import platform
import shutil
import os
import sys

source = sys.argv[1]
version = "0.5.0-dev"
packages = [("files", 0)]
dist_name = "Emojicode-{0}-{1}-{2}".format(version, platform.system(),
platform.machine())
path = dist_name

if __name__ == "__main__":
if os.path.exists(path):
shutil.rmtree(path)
os.makedirs(path)

shutil.copy2(os.path.join(source, "install.sh"),
os.path.join(path, "install.sh"))
os.makedirs(os.path.join(path, "packages", "s"))
shutil.copy2(os.path.join(source, "headers", "s.emojic"),
os.path.join(path, "packages", "s", "header.emojic"))

for package, version in packages:
dir_path = os.path.join(path, "packages", package)
os.makedirs(dir_path)
shutil.copy2(os.path.join(source, "headers", package + ".emojic"),
os.path.join(path, "packages", package, "header.emojic"))
symlink_name = os.path.join(path, "packages",
"{0}-v{1}".format(package, version))
os.symlink(package, symlink_name)
# TODO: Copy binaries

shutil.copy2("emojicode", os.path.join(path, "emojicode"))
shutil.copy2("emojicodec", os.path.join(path, "emojicodec"))
shutil.make_archive(dist_name, "gztar", path)
74 changes: 74 additions & 0 deletions tests.py
@@ -0,0 +1,74 @@
from subprocess import *
import glob
import os
import dist

os.environ["EMOJICODE_PACKAGES_PATH"] = os.path.join(dist.path, "packages")

compilation_tests = [
"hello", "intTest", "branch", "namespace", "enum", "unwrap",
"conditionalProduce", "piglatin", "stringConcat", "extension", "class",
"babyBottleInitializer", "valueType", "isNothingness", "downcastClass",
"protocol", "callable", "threads", "variableInitAndScoping"
# gcStressTest chaining
]
library_tests = [
"stringTest", "primitives", "mathTest", "listTest", "rangeTest",
"dataTest", "dictionaryTest", "systemTest", "jsonTest", "enumerator"
# fileTest
]
reject_tests = glob.glob(os.path.join(dist.source, "tests", "reject,",
"*.emojic"))

failed_tests = []


def fail_test(name):
global failed_tests
print("🛑 {0} failed".format(name))
failed_tests.append(name)


def test_paths(name, kind):
return (os.path.join(dist.source, "tests", kind, name + ".emojic"),
os.path.join(dist.source, "tests", kind, name + ".emojib"))


def library_test(name):
source_path, binary_path = test_paths(name, 's')

run(["./emojicodec", source_path], check=True)
completed = run(["./emojicode", binary_path], stdout=PIPE)
if completed.returncode != 0:
fail_test(name)
print(completed.stdout.decode('utf-8'))


def compilation_test(name):
source_path, binary_path = test_paths(name, 'compilation')

run(["./emojicodec", source_path], check=True)
completed = run(["./emojicode", binary_path], stdout=PIPE)
exp_path = os.path.join(dist.source, "tests", "compilation", name + ".txt")
if completed.stdout.decode('utf-8') != open(exp_path, "r").read():
fail_test(name)


def reject_test(filename):
completed = run(["./emojicodec", filename], stderr=DEVNULL)
if completed.returncode == 0:
fail_test(filename)


for test in compilation_tests:
compilation_test(test)
for test in reject_tests:
reject_test(test)
for test in library_tests:
library_test(test)

if len(failed_tests) == 0:
print("✅ ✅ All tests passed.")
else:
print("🛑 🛑 {0} tests failed: {1}".format(len(failed_tests),
", ".join(failed_tests)))

0 comments on commit dd0f8ed

Please sign in to comment.