Added the ability to test/build in Unix

This commit is contained in:
Aaron Helton
2019-10-23 22:24:27 -04:00
parent 6ef34bf42f
commit 7fb400ee4f
3 changed files with 40 additions and 6 deletions

1
.gitignore vendored
View File

@@ -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

View File

@@ -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
)
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()

24
test/Test.sh Executable file
View File

@@ -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