Skip to content
Snippets Groups Projects
Commit 26727767 authored by Taddeus Kroes's avatar Taddeus Kroes
Browse files

Added unit testing framework.

parent 02c89c74
No related branches found
No related tags found
No related merge requests found
*.swp
*.pdf
*~
.coverage
coverage/
build/
src/Makefile_old
Makefile 0 → 100644
BUILD=build/
# Fix pdflatex search path
TGT_DIR :=
TGT_DOC :=
# Default target is 'all'. The 'build' target is defined here so that all
# sub rules.mk can add prerequisites to the 'build' target.
all:
build:
d := tests/
include base.mk
include $(d)/rules.mk
.PHONY: doc
all: doc build
clean:
rm -rf $(CLEAN)
$(TGT_DIR):
mkdir -p $(TGT_DIR)
b := $(BUILD)$(d)
TGT_DIR := $(TGT_DIR) $(b)
CLEAN := $(CLEAN) $(b)
CC=gcc
LEX=lex
YACC=yacc
CFLAGS = -std=c99 -pedantic -Wall -D_POSIX_SOURCE -D_GNU_SOURCE $(PIC) -pipe
all: peephole
peephole: y.tab.o lex.yy.o
$(CC) -o $@ $^ -lm
y.tab.c y.tab.h: peephole.y
$(YACC) -d $^
lex.yy.c: peephole.l
$(LEX) $^
clean:
rm -f lex.yy.* y.tab.* *.o peephole parser.out parsetab.py
from testrunner import main
import sys
main(sys.argv[1:])
File added
TESTS=$(wildcard tests/test_*.py)
COVERAGE_OUTPUT_DIR := coverage
PROFILER_OUTPUT_DIR := profiles
OMIT := /usr/share/pyshared/*,/usr/lib/pymodules/python2.7/sympy/*,test*,*__init__.py
ifeq ($(findstring python-coverage,$(wildcard /usr/bin/*)), python-coverage)
COVERAGE=/usr/bin/python-coverage
RM=rm -rf
else
COVERAGE=/usr/bin/coverage
endif
CLEAN := $(CLEAN) $(COVERAGE_OUTPUT_DIR) $(PROFILER_OUTPUT_DIR)
TGT_DIR := $(TGT_DIR) $(PROFILER_OUTPUT_DIR)
.PHONY: test coverage $(TESTS)
test: $(TESTS) build
ifeq ($(findstring python-coverage,$(wildcard /usr/bin/*)), python-coverage)
coverage: ${COVERAGE} build
${COVERAGE} erase
${RM} ${COVERAGE_OUTPUT_DIR}/*
mkdir ${COVERAGE_OUTPUT_DIR} 2>/dev/null || true
for t in ${TESTS}; do \
echo $$t; \
${COVERAGE} -x test.py $$t; \
${COVERAGE} combine; \
done
${COVERAGE} html --omit=${OMIT} -d ${COVERAGE_OUTPUT_DIR}
else
coverage: ${COVERAGE} build
mkdir ${COVERAGE_OUTPUT_DIR} 2>/dev/null || true
${COVERAGE} erase
for t in ${TESTS}; do \
echo $$t; \
${COVERAGE} --omit ${OMIT} -x test.py $$t; \
${COVERAGE} --omit ${OMIT} -c; \
done
${COVERAGE} html --omit ${OMIT} --dir ${COVERAGE_OUTPUT_DIR}
endif
${COVERAGE}:
@echo "Install package 'python-coverage' to generate a coverage report."
@echo "On Debian/Ubuntu use: sudo apt-get install python-coverage"; false
$(TESTS): build; @python -m testrunner $@
import unittest
from src.utils import Statement as S, Block as B, find_leaders, \
find_basic_blocks
class TestUtils(unittest.TestCase):
def setUp(self):
pass
def test_find_leaders(self):
add = S('command', 'add', '$1', '$2', '$3')
s = [add, S('command', 'j', 'foo'), add, add, S('label', 'foo')]
self.assertEqual(find_leaders(s), [0, 2, 4])
def test_find_basic_blocks(self):
add = S('command', 'add', '$1', '$2', '$3')
s = [add, S('command', 'j', 'foo'), add, add, S('label', 'foo')]
self.assertEqual(map(lambda b: b.statements, find_basic_blocks(s)), \
[B(s[:2]).statements, B(s[2:4]).statements, \
B(s[4:]).statements])
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment