#!/bin/bash
source ./test-helpers.sh
FILE_NAME=`./getBinaryName.sh`
chmod +x ./dist/$FILE_NAME
echo "Running samples to console"
./dist/$FILE_NAME ./sample-projects/ > console_test.txt
test_report 'console' 'console_test.txt' "${lines_to_find[@]}"
rm console_test.txt
echo "Running samples to HTML report"
./dist/$FILE_NAME ./sample-projects/ --output test.html
test_report 'html' 'test.html' "${lines_to_find[@]}"
rm test.html
echo "Running samples to Dependency Report"
declare -a dependencies=("componentversionoriginfilename"
"junit4.8.2"
"zstd-jni1.1.0"
"snappy-java1.1.3"
"lz4-java1.4.0"
"hadoop-lzo0.4.17"
"leveldbjni-all1.8"
"CommandLineParser2.8.0"
"Microsoft.Build.Utilities.Core17.1.0"
"Microsoft.Extensions.Logging.Console6.0.0"
"Microsoft.NET.Test.Sdk16.5.0"
"Microsoft.VisualStudio.Setup.Configuration.Interop3.1.2196"
"System.Linq.Async6.0.1"
"xunit2.4.1"
"coverlet.collector1.2.0"
"SciPy"
"NumPy"
"FakeDependency1.2.3"
"cors2.8.5"
"express4.18.1"
"rxjs7.5.6"
"socket.io4.5.1"
"@codechecks/client0.1.12"
"@commitlint/cli17.0.3"
"eslint7.32.0"
"typescript4.7.4"
"github.com/aws/aws-sdk-go"
"github.com/golang/snappy"
"rails6.1.6.1"
"rake11.1"
"actionpack"
"bcrypt3.1"
"cucumber4.1"
"gc_tracer"
"gssapi"
"mail"
"turbo-rails"
"httpclient"
"jruby-openssl"
)
./dist/$FILE_NAME ./sample-projects/ --output test.xlsx --output-format dependencies
# xlsx files are compressed files, so we need to unzip them and then compare them
mkdir ./temp
unzip -q ./test.xlsx -d ./temp
test_report 'dependencies' './temp/xl/sharedStrings.xml' "${dependencies[@]}"
rm test.xlsx
rm -rf ./temp
echo "--- Running negative tests ---"
echo "Running missing arguments test"
./dist/$FILE_NAME 2>&1 | tee missing_arguments_test.txt
if diff "./tests-baseline/missing_arguments_test.txt" "missing_arguments_test.txt"; then
echo "**PASSED** missing arguments test"
else
echo "**FAILED**: missing arguments test" && exit 1
fi
rm missing_arguments_test.txt
echo "Running directory not found test"
./dist/$FILE_NAME unexisting_directory 2>&1 | tee directory_not_found_test.txt
if diff "./tests-baseline/directory_not_found_test.txt" "directory_not_found_test.txt"; then
echo "**PASSED** directory not found test"
else
echo "**FAILED**: directory not found test" && exit 1
fi
rm directory_not_found_test.txt