From 7fb400ee4fc9f90d1b5021191b6b2547055c18ef Mon Sep 17 00:00:00 2001 From: Aaron Helton Date: Wed, 23 Oct 2019 22:24:27 -0400 Subject: [PATCH] Added the ability to test/build in Unix --- .gitignore | 1 + CMakeLists.txt | 21 +++++++++++++++------ test/Test.sh | 24 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100755 test/Test.sh diff --git a/.gitignore b/.gitignore index cdcaae8..4a15c31 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ cmake-build-debug/ /test/output.txt /test/output2.txt /test/NameSort.exe +/test/NameSort # Ignore build directory on *nix systems /build diff --git a/CMakeLists.txt b/CMakeLists.txt index ae256e3..1f0fc4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,9 +15,18 @@ add_custom_command(TARGET NameSort POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ target_include_directories(NameSort PRIVATE ${CMAKE_SOURCE_DIR}/include) # After everything has been built, we want to automatically run tests as part of the build -add_custom_command( - TARGET NameSort - POST_BUILD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test - COMMAND cmd /c Test.cmd -) \ No newline at end of file +IF(Win32) + add_custom_command( + TARGET NameSort + POST_BUILD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test + COMMAND cmd /c Test.cmd + ) +ELSE() + add_custom_command( + TARGET NameSort + POST_BUILD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test + COMMAND bash -c ./Test.sh + ) +ENDIF() diff --git a/test/Test.sh b/test/Test.sh new file mode 100755 index 0000000..9928a7c --- /dev/null +++ b/test/Test.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +OUTPUT="output.txt" +OUTPUT2="output2.txt" + +rm -f $OUTPUT +rm -f $OUTPUT2 + +./NameSort "Sort Me.txt" > $OUTPUT +./NameSort "Sort Me 2.txt" > $OUTPUT2 + +diff "Sorted.txt" $OUTPUT +if [ $? -eq 0 ]; then + echo "Test 1 Success" +else + echo "Test 1 Failure" +fi + +diff "Sorted 2.txt" $OUTPUT2 +if [ $? -eq 0 ]; then + echo "Test 2 Success" +else + echo "Test 2 Failure" +fi