From 8c153b5321ddd05fdd7fdf9c4b4c55a99ad891d3 Mon Sep 17 00:00:00 2001
From: Abdelrahman Said <said.abdelrahman89@gmail.com>
Date: Sun, 9 Jun 2024 22:31:14 +0100
Subject: [PATCH] Build tests on Windows

---
 build.ps1 | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/build.ps1 b/build.ps1
index 34dfd1d..1d79641 100644
--- a/build.ps1
+++ b/build.ps1
@@ -3,11 +3,16 @@ Param(
 )
 
 $Compiler = "cl.exe"
+
 $GeneralFlags = "/Wall /WX /wd4996"
 $LibraryFlags = "/LD"
+
 $IncludeDirs = Get-ChildItem -Path src -Recurse -Directory -ErrorAction SilentlyContinue -Force | %{$("/I " + '"' + $_.FullName + '"')}
 $SrcFiles = Get-ChildItem -Path src -Recurse -Filter *.c -ErrorAction SilentlyContinue -Force | %{$('"' + $_.FullName + '"')}
 
+$TestIncludeDirs = Get-ChildItem -Path tests -Recurse -Directory -ErrorAction SilentlyContinue -Force | %{$("/I " + '"' + $_.FullName + '"')}
+$TestSrcFiles = Get-ChildItem -Path tests -Recurse -Filter *.c -ErrorAction SilentlyContinue -Force | %{$('"' + $_.FullName + '"')}
+
 If ($Release -eq $True) {
 	$GeneralFlags += " /O2 /Og"
 	$BuildType = "release"
@@ -19,15 +24,25 @@ If ($Release -eq $True) {
 $BuildDir = "./libwapp-build/windows-$BuildType"
 $ObjDir = "$BuildDir/objects"
 $OutDir = "$BuildDir/output"
+$TestsDir = "$BuildDir/tests"
+
 $OutBasename = "libwapp"
 $Objects = "/Fo:$ObjDir/"
 $Outputs = "/Fd:$OutDir/$OutBasename /Fe:$OutDir/$OutBasename"
 
+$TestOutBasename = "wapptest"
+$TestOutputs = "/Fo:$TestsDir/ /Fe:$TestsDir/$TestOutBasename"
+
 If (Test-Path $BuildDir) {
 	Remove-Item $BuildDir -Recurse -Force
 }
 
 mkdir -p $ObjDir > $null
 mkdir -p $OutDir > $null
+mkdir -p $TestsDir > $null
 
+# Build and run tests
+Invoke-Expression "$Compiler $GeneralFlags $IncludeDirs $TestIncludeDirs $SrcFiles $TestSrcFiles $TestOutputs"
+
+# Build library
 Invoke-Expression "$Compiler $GeneralFlags $LibraryFlags $IncludeDirs $SrcFiles $Objects $Outputs"