Use doctest as test framework
This commit is contained in:
parent
b64c82ec92
commit
eb6faab89f
6 changed files with 7148 additions and 18 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
|||
*.o
|
||||
/vgbc
|
||||
/libemu.a
|
||||
/vgbc.test
|
||||
|
|
22
Makefile
22
Makefile
|
@ -1,9 +1,8 @@
|
|||
include Makeconf
|
||||
|
||||
emu-objs := $(addsuffix .o,$(modules))
|
||||
test-targets := $(patsubst %,tests/%.bin, $(tests))
|
||||
|
||||
clean-objs := $(emu-objs) $(test-targets) libemu.a vgbc
|
||||
clean-objs := $(emu-objs) libemu.a vgbc vgbc.test
|
||||
test-srcs := $(wildcard tests/*.cpp)
|
||||
|
||||
.PHONY: all test clean
|
||||
|
||||
|
@ -12,15 +11,8 @@ all: vgbc $(test-targets)
|
|||
clean:
|
||||
rm -rf $(clean-objs)
|
||||
|
||||
test: $(test-targets)
|
||||
@for test in $(tests); do \
|
||||
if ./tests/$$test.bin; then \
|
||||
echo "-- $$test successful"; \
|
||||
else \
|
||||
echo "-- $$test failed"; \
|
||||
exit 1; \
|
||||
fi \
|
||||
done
|
||||
test: vgbc.test
|
||||
@./$< -s
|
||||
|
||||
%.o: %.cpp
|
||||
g++ $(CXX_FLAGS) -c -o $@ $^
|
||||
|
@ -28,8 +20,8 @@ test: $(test-targets)
|
|||
libemu.a: $(emu-objs)
|
||||
ar -rc $@ $^
|
||||
|
||||
tests/%.bin: tests/%.cpp libemu.a
|
||||
g++ $(CXX_FLAGS) -o $@ $^
|
||||
|
||||
vgbc: main.c libemu.a
|
||||
g++ $(CXX_FLAGS) -o $@ $^
|
||||
|
||||
vgbc.test: $(test-srcs) libemu.a
|
||||
g++ $(CXX_FLAGS) -o $@ $^
|
||||
|
|
2
tests/doctest.cpp
Normal file
2
tests/doctest.cpp
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
7106
tests/doctest.h
Normal file
7106
tests/doctest.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,8 +1,9 @@
|
|||
#include <iostream>
|
||||
#include "doctest.h"
|
||||
|
||||
#include "memory/bus.h"
|
||||
#include "memory/ram.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
TEST_CASE("Bus can map same device twice")
|
||||
{
|
||||
RAM r(0x1000);
|
||||
Bus b;
|
||||
|
@ -11,5 +12,5 @@ int main(int argc, char** argv)
|
|||
b.map_device(0x2000, 0x2FFF, &r);
|
||||
|
||||
b.write8(0x60, 42);
|
||||
return (b.read8(0x2060) == 42) ? 0 : 1;
|
||||
CHECK(b.read8(0x2060) == 42);
|
||||
}
|
||||
|
|
27
tests/test_cpu_simple.cpp
Normal file
27
tests/test_cpu_simple.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "doctest.h"
|
||||
|
||||
#include "cpu/cpu.h"
|
||||
#include "memory/ram.h"
|
||||
|
||||
|
||||
TEST_CASE("simple load and add")
|
||||
{
|
||||
u8 test_ram[] = {
|
||||
0x3E, 0x10, // LD A, $0x10
|
||||
0x87, // ADD A, A
|
||||
};
|
||||
RAM r(test_ram, 3, true);
|
||||
Cpu cpu(&r);
|
||||
|
||||
CHECK(cpu.state.PC == 0x0);
|
||||
|
||||
cpu.step();
|
||||
|
||||
CHECK(cpu.state.PC == 0x2);
|
||||
CHECK(cpu.state.A == 0x10);
|
||||
|
||||
cpu.step();
|
||||
|
||||
CHECK(cpu.state.PC == 0x3);
|
||||
CHECK(cpu.state.A == 0x20);
|
||||
}
|
Loading…
Reference in a new issue