diff --git a/.gitignore b/.gitignore index 2042aa7c8c..395f0f8a58 100644 --- a/.gitignore +++ b/.gitignore @@ -70,4 +70,8 @@ StyleCopViolations.xml # SublimeText *.sublime-project -*.sublime-workspace \ No newline at end of file +*.sublime-workspace + +# NUnit +/TestResult.xml +/lib/ \ No newline at end of file diff --git a/Makefile b/Makefile index a49724fde2..9ac467a218 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,11 @@ # to compile with development tools, run: # make all [DEBUG=false] # +# to check unit tests (requires NUnit version >= 2.6), run: +# make nunit [NUNIT_CONSOLE=] [NUNIT_LIBS_PATH=] [NUNIT_LIBS=] +# Use NUNIT_CONSOLE if nunit[2|3]-console was not downloaded by `make dependencies` nor is it not in bin search paths +# Use NUNIT_LIBS_PATH if NUnit libs are not in search paths. Include trailing / +# Use NUNIT_LIBS if NUnit libs have different names (such as including a prefix or suffix) # to check the official mods for erroneous yaml files, run: # make test # @@ -41,6 +46,8 @@ CSC = dmcs CSFLAGS = -nologo -warn:4 -codepage:utf8 -unsafe -warnaserror DEFINE = TRACE COMMON_LIBS = System.dll System.Core.dll System.Data.dll System.Data.DataSetExtensions.dll System.Drawing.dll System.Xml.dll thirdparty/download/ICSharpCode.SharpZipLib.dll thirdparty/download/FuzzyLogicLibrary.dll thirdparty/download/Mono.Nat.dll thirdparty/download/MaxMind.Db.dll thirdparty/download/MaxMind.GeoIP2.dll thirdparty/download/Eluant.dll thirdparty/download/SmarIrc4net.dll +NUNIT_LIBS_PATH := +NUNIT_LIBS := $(NUNIT_LIBS_PATH)nunit.framework.dll DEBUG = true ifeq ($(DEBUG), $(filter $(DEBUG),false no n off 0)) @@ -129,6 +136,16 @@ mod_common_LIBS = $(COMMON_LIBS) $(STD_MOD_LIBS) thirdparty/download/StyleCop.dl PROGRAMS += mod_common mod_common: $(mod_common_TARGET) +# NUnit testing +test_dll_SRCS := $(shell find OpenRA.Test/ -iname '*.cs') +test_dll_TARGET = OpenRA.Test.dll +test_dll_KIND = library +test_dll_DEPS = $(game_TARGET) +test_dll_FLAGS = -warn:1 +test_dll_LIBS = $(COMMON_LIBS) $(game_TARGET) $(NUNIT_LIBS) thirdparty/download/StyleCop.dll thirdparty/download/StyleCop.CSharp.dll thirdparty/download/StyleCop.CSharp.Rules.dll +PROGRAMS += test_dll +test_dll: $(test_dll_TARGET) + ##### Official Mods ##### STD_MOD_LIBS = $(game_TARGET) @@ -211,6 +228,23 @@ check: utility mods @echo "Checking for code style violations in OpenRA.Test..." @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Test +NUNIT_CONSOLE := $(shell test -f thirdparty/download/nunit-console.exe && echo mono thirdparty/download/nunit-console.exe || \ + which nunit2-console 2>/dev/null || which nunit3-console 2>/dev/null || which nunit-console 2>/dev/null) +nunit: test_dll + @echo + @echo "Checking unit tests..." + @if [ "$(NUNIT_CONSOLE)" = "" ] ; then \ + echo 'nunit[2|3]-console not found!'; \ + echo 'Was "make dependencies" called or is NUnit installed?'>&2; \ + echo 'see "make help"'; \ + exit 1; \ + fi + @if $(NUNIT_CONSOLE) --help | head -n 1 | grep -E "NUnit version (1|2\.[0-5])";then \ + echo 'NUnit version >= 2.6 required'>&2; \ + exit 1; \ + fi + @$(NUNIT_CONSOLE) $(test_dll_TARGET) + test: utility mods @echo @echo "Testing Tiberian Sun mod MiniYAML..." @@ -438,32 +472,38 @@ uninstall: @-$(RM_F) "$(DESTDIR)$(mandir)/man6/openra.6" help: - @echo to compile, run: - @echo \ \ make [DEBUG=false] + @echo 'to compile, run:' + @echo ' make [DEBUG=false]' @echo - @echo to compile with development tools, run: - @echo \ \ make all [DEBUG=false] + @echo 'to compile with development tools, run:' + @echo ' make all [DEBUG=false]' @echo - @echo to check the official mods for erroneous yaml files, run: - @echo \ \ make test + @echo 'to check unit tests (requires NUnit version >= 2.6), run:' + @echo ' make nunit [NUNIT_CONSOLE=] [NUNIT_LIBS_PATH=] [NUNIT_LIBS=]' + @echo ' Use NUNIT_CONSOLE if nunit[2|3]-console was not downloaded by `make dependencies` nor is it not in bin search paths' + @echo ' Use NUNIT_LIBS_PATH if NUnit libs are not in search paths. Include trailing /' + @echo ' Use NUNIT_LIBS if NUnit libs have different names (such as including a prefix or suffix)' @echo - @echo to generate documentation aimed at modders, run: - @echo \ \ make docs + @echo 'to check the official mods for erroneous yaml files, run:' + @echo ' make test' @echo - @echo to install, run: - @echo \ \ make \[prefix=/foo\] \[bindir=/bar/bin\] install + @echo 'to generate documentation aimed at modders, run:' + @echo ' make docs' @echo - @echo to install with development tools, run: - @echo \ \ make \[prefix=/foo\] \[bindir=/bar/bin\] install-all + @echo 'to install, run:' + @echo ' make [prefix=/foo] [bindir=/bar/bin] install' @echo - @echo to install Linux startup scripts, desktop files and icons - @echo \ \ make install-linux-shortcuts [DEBUG=false] + @echo 'to install with development tools, run:' + @echo ' make [prefix=/foo] [bindir=/bar/bin] install-all' @echo - @echo to uninstall, run: - @echo \ \ make uninstall + @echo 'to install Linux startup scripts, desktop files and icons' + @echo ' make install-linux-shortcuts [DEBUG=false]' @echo - @echo to start the game, run: - @echo \ \ openra + @echo 'to uninstall, run:' + @echo ' make uninstall' + @echo + @echo 'to start the game, run:' + @echo ' openra' @@ -474,4 +514,4 @@ help: .SUFFIXES: -.PHONY: core tools package all mods clean distclean dependencies version $(PROGRAMS) +.PHONY: core tools package all mods clean distclean dependencies version $(PROGRAMS) nunit diff --git a/thirdparty/fetch-thirdparty-deps.sh b/thirdparty/fetch-thirdparty-deps.sh index bc7f14bc09..847e29be39 100755 --- a/thirdparty/fetch-thirdparty-deps.sh +++ b/thirdparty/fetch-thirdparty-deps.sh @@ -78,6 +78,16 @@ if [ ! -f nunit.framework.dll ]; then rm -rf NUnit fi +if [ ! -f nunit-console.exe ]; then + echo "Fetching NUnit.Runners from NuGet" + get NUnit.Runners 2.6.4 + cp ./NUnit.Runners/tools/nunit-console.exe . + chmod +x nunit-console.exe + cp ./NUnit.Runners/tools/nunit-console.exe.config . + cp -R ./NUnit.Runners/tools/lib . + rm -rf NUnit.Runners +fi + if [ ! -f Mono.Nat.dll ]; then echo "Fetching Mono.Nat from NuGet" get Mono.Nat 1.2.21 @@ -107,4 +117,4 @@ if [ ! -f SmarIrc4net.dll ]; then get SmartIrc4net 0.4.5.1 cp ./SmartIrc4net/lib/net40/SmarIrc4net* . rm -rf SmartIrc4net -fi \ No newline at end of file +fi