Skip to content

Commit 84c6969

Browse files
committed
add tests to launchers
1 parent b01a91f commit 84c6969

File tree

4 files changed

+126
-13
lines changed

4 files changed

+126
-13
lines changed

.github/workflows/launchers.yml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ jobs:
1414
java-version: '17'
1515
distribution: 'temurin'
1616
cache: 'sbt'
17-
- name: Build the launcher command
18-
run: sbt "dist-linux-x86_64/pack"
19-
- run: ./dist/linux-x86_64/target/pack/bin/scala --version
17+
- name: Build and test launcher command
18+
run: ./project/scripts/native-integration/bashTests
19+
env:
20+
LAUNCHER_EXPECTED_PROJECT: "dist-linux-x86_64"
2021

2122
linux-aarch64:
2223
name: Deploy and Test on Linux ARM64 architecture
@@ -33,9 +34,10 @@ jobs:
3334
# https://github.com/actions/runner-images/issues/9369
3435
- name: Install sbt
3536
run: brew install sbt
36-
- name: Build the launcher command
37-
run: sbt "dist-linux-aarch64/pack"
38-
- run: ./dist/linux-aarch64/target/pack/bin/scala --version
37+
- name: Build and test launcher command
38+
run: ./project/scripts/native-integration/bashTests
39+
env:
40+
LAUNCHER_EXPECTED_PROJECT: "dist-linux-aarch64"
3941

4042
mac-x86_64:
4143
name: Deploy and Test on Mac x64 architecture
@@ -51,9 +53,10 @@ jobs:
5153
# https://github.com/actions/runner-images/issues/9369
5254
- name: Install sbt
5355
run: brew install sbt
54-
- name: Build the launcher command
55-
run: sbt "dist-mac-x86_64/pack"
56-
- run: ./dist/mac-x86_64/target/pack/bin/scala --version
56+
- name: Build and test launcher command
57+
run: ./project/scripts/native-integration/bashTests
58+
env:
59+
LAUNCHER_EXPECTED_PROJECT: "dist-mac-x86_64"
5760

5861
mac-aarch64:
5962
name: Deploy and Test on Mac ARM64 architecture
@@ -69,9 +72,10 @@ jobs:
6972
# https://github.com/actions/runner-images/issues/9369
7073
- name: Install sbt
7174
run: brew install sbt
72-
- name: Build the launcher command
73-
run: sbt "dist-mac-aarch64/pack"
74-
- run: ./dist/mac-aarch64/target/pack/bin/scala --version
75+
- name: Build and test launcher command
76+
run: ./project/scripts/native-integration/bashTests
77+
env:
78+
LAUNCHER_EXPECTED_PROJECT: "dist-mac-aarch64"
7579

7680
win-x86_64:
7781
name: Deploy and Test on Windows x64 architecture
@@ -86,4 +90,6 @@ jobs:
8690
cache: 'sbt'
8791
- name: Build the launcher command
8892
run: sbt "dist-win-x86_64/pack"
89-
- run: ./dist/win-x86_64/target/pack/bin/scala --version
93+
- name: Run the launcher command tests
94+
run: './project/scripts/native-integration/winTests.bat'
95+
shell: cmd
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
#/*---------------*\
6+
# * SETUP VARS *#
7+
# *---------------*/
8+
9+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/../../.."
10+
11+
SBT="$ROOT/project/scripts/sbt" # if run on CI
12+
# SBT="sbt" # if run locally
13+
14+
# set the $DIST_PROJECT and $DIST_DIR variables
15+
source "$ROOT/bin/common-platform"
16+
17+
die () {
18+
echo >&2 "$@"
19+
exit 1
20+
}
21+
22+
PROG_HOME="$DIST_DIR/target/pack"
23+
24+
SOURCE="$ROOT/tests/pos/HelloWorld.scala"
25+
SOURCE_VERSION="$ROOT/project/scripts/native-integration/reportScalaVersion.scala"
26+
27+
clear_cli_dotfiles()
28+
{
29+
local out="$1"
30+
rm -rf "$out"/.bsp
31+
rm -rf "$out"/.scala-build
32+
33+
rm -f "$ROOT"/.bsp/scala.json
34+
if [ -z "$(ls -A "$ROOT"/.bsp)" ]; then
35+
rm -rf "$ROOT"/.bsp
36+
fi
37+
rm -rf "$ROOT"/.scala-build
38+
}
39+
40+
#/*---------------*\
41+
# * INITIALIZE *#
42+
# *---------------*/
43+
44+
# build the distribution
45+
"$SBT" "$DIST_PROJECT/pack"
46+
47+
SCALA_VERSION=""
48+
# iterate through lines in VERSION_SRC
49+
while IFS= read -r line; do
50+
# if line starts with "version:=" then extract the version
51+
if [[ "$line" == version:=* ]]; then
52+
SCALA_VERSION="${line#version:=}"
53+
break
54+
fi
55+
done < "$PROG_HOME/VERSION"
56+
57+
if [ -z "$SCALA_VERSION" ]; then
58+
die "Could not find scala version in $PROG_HOME/VERSION"
59+
fi
60+
61+
#/*-------------------*\
62+
# * TESTING BEGINS *#
63+
# *-------------------*/
64+
65+
echo "assert native launcher matches expected version"
66+
if [ -z "$LAUNCHER_EXPECTED_PROJECT" ]; then
67+
die "LAUNCHER_EXPECTED_PROJECT is not set in the environment"
68+
fi
69+
test "$LAUNCHER_EXPECTED_PROJECT" = "$DIST_PROJECT"
70+
71+
echo "testing version output (default)"
72+
std_output=$("$PROG_HOME/bin/scala" version --scala-version)
73+
test "$SCALA_VERSION" = "$std_output"
74+
75+
echo "testing run command"
76+
std_output=$("$PROG_HOME/bin/scala" run "$SOURCE" --power --offline --server=false)
77+
test "hello world" = "$std_output"
78+
clear_cli_dotfiles "$ROOT/tests/pos"
79+
80+
echo "testing run command (-with-compiler)"
81+
std_output=$("$PROG_HOME/bin/scala" run "$SOURCE_VERSION" -with-compiler --power --offline --server=false)
82+
test "$SCALA_VERSION" = "$std_output"
83+
clear_cli_dotfiles "$ROOT/project/scripts/native-integration"
84+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// To be ran by Scala CLI (requires -with-compiler command line option)
2+
3+
@main def reportScalaVersion: Unit =
4+
println(dotty.tools.dotc.config.Properties.versionNumberString)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@echo off
2+
setlocal
3+
4+
@rem paths are relative to the root project directory
5+
set "_PREFIX=dist\win-x86_64\target\pack"
6+
set "_SOURCE=tests\pos\HelloWorld.scala"
7+
set "_OUT_DIR=out"
8+
9+
@rem if-tests mimic the non-existing bash instruction 'set -e'.
10+
call "%_PREFIX%\bin\scalac.bat" "@project\scripts\options" "%_SOURCE%"
11+
if not %ERRORLEVEL%==0 endlocal& exit /b 1
12+
13+
call "%_PREFIX%\bin\scalac.bat" -d "%_OUT_DIR%" "%_SOURCE%"
14+
if not %ERRORLEVEL%==0 endlocal& exit /b 1
15+
16+
call "%_PREFIX%\bin\scala.bat" --power -classpath "%_OUT_DIR%" -M HelloWorld --offline --server=false
17+
if not %ERRORLEVEL%==0 endlocal& exit /b 1
18+
19+
endlocal

0 commit comments

Comments
 (0)