#!/usr/bin/env bash

set -eo pipefail
source debian/tests/.tests.rc.d/init.sh

ChangeToAutopkgtestTmpFolder

for LANGUAGE in "${DOTNET_LANGUAGES[@]}"; do
    LogInfo "Creating $LANGUAGE console template"
    dotnet new console --name "HelloWorld" --language $LANGUAGE
    cd "HelloWorld"

    LogInfo "Building Project"
    dotnet build

    LogInfo "Running Project"    
    dotnet run | tee stdout.log

    LogInfo "Comparing with expected output"
    case "$LANGUAGE" in 
        C#)
            test "$(< stdout.log)" = "$(echo -e 'Hello, World!\n')"
            ;;
        F#) 
            test "$(< stdout.log)" = "$(echo -e 'Hello from F#\n')"
            ;;
        VB) 
            test "$(< stdout.log)" = "$(echo -e 'Hello World!\n')"
            ;;
    esac

    LogInfo "Cleaning up"
    cd ..
    rm -r "HelloWorld"
done

LogInfo "Test Ok!"
