##################################################################################################################
# Note about the *-fail.txt files:
# Because scripted tests run in a random /tmp/sbt_.../ folder we can't check the absolute file names in the HTML:
# E.g. "<pre data-file="/tmp/sbt_edc0df79/..."
##################################################################################################################

# Clean up in case there was a failed run before
$ delete ../dev-mode-compile-and-config-error-source-sub-project-outside

# Move the sub project out of the project's base directory.
# Such an outside subproject is needed to test sbt 1.4+ virtual files with absolute paths.
# Files _within_ the project's base directory on the other hand use relative paths with a ${BASE} prefix.
$ copy dev-mode-compile-and-config-error-source-sub-project-outside/build.sbt ../
$ copy dev-mode-compile-and-config-error-source-sub-project-outside/src/main/scala/Bar.java ../
$ delete dev-mode-compile-and-config-error-source-sub-project-outside

# Now that we have setup the outside subproject let's use the new build.sbt which references that outside subproject
$ copy-file build.sbt.1 build.sbt
$ delete build.sbt.1

# Reload the new build.sbt
> reload

# Let's start the tests
> compile
> run

################
# Invalid config
################
$ copy-file conf/application.conf application.conf.good
$ copy-file application.conf.bad conf/application.conf
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> makeRequestAndRecordResponseBody / appconf-fail.txt
> checkLinesPartially appconf-fail.txt target/appconf-fail.txt
> checkLinesPartiallyNotContain blacklist.txt target/appconf-fail.txt
$ copy-file application.conf.good conf/application.conf
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> verifyResourceContains / 200 "app compiles and runs!"

###########################################################################################################################################
# Invalid routes (parsing the routes file will fail already, no scala file gets generated, scalac compilation does not even take place yet)
###########################################################################################################################################
$ copy-file conf/routes routes.good
$ copy-file routes.bad conf/routes
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> makeRequestAndRecordResponseBody / routes-fail.txt
> checkLinesPartially routes-fail.txt target/routes-fail.txt
> checkLinesPartiallyNotContain blacklist.txt target/routes-fail.txt
$ copy-file routes.good conf/routes
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> verifyResourceContains / 200 "app compiles and runs!"

###################################################################################################################
# Invalid routes (parsing the routes file is OK, but compiling target/scala-*/routes/main/router/Routes.scala fails)
# Actually this tests if the sourcePositionMappers set up for the routes compiler is called and works correctly
###################################################################################################################
$ copy-file conf/routes routes.good
$ copy-file routes-2.bad conf/routes
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> makeRequestAndRecordResponseBody / routes-fail-2.txt
> checkLinesPartially routes-fail-2.txt target/routes-fail-2.txt
> checkLinesPartiallyNotContain blacklist.txt target/routes-fail-2.txt
$ copy-file routes.good conf/routes
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> verifyResourceContains / 200 "app compiles and runs!"

##################
# Invalid messages
##################
$ copy-file conf/messages messages.good
$ copy-file messages.bad conf/messages
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> makeRequestAndRecordResponseBody / messages-fail.txt
> checkLinesPartially messages-fail.txt target/messages-fail.txt
> checkLinesPartiallyNotContain blacklist.txt target/messages-fail.txt
$ copy-file messages.good conf/messages
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> verifyResourceContains / 200 "app compiles and runs!"

#########################################################################################################################################################
# Invalid twirl template (parsing the *.scala.html file will fail already, no scala file gets generated, scalac compilation does not even take place yet)
#########################################################################################################################################################
$ copy-file app/views/index.scala.html index.scala.html.good
$ copy-file index.scala.html.bad app/views/index.scala.html
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> makeRequestAndRecordResponseBody / twirl-fail.txt
> checkLinesPartially twirl-fail.txt target/twirl-fail.txt
> checkLinesPartiallyNotContain blacklist.txt target/twirl-fail.txt
$ copy-file index.scala.html.good app/views/index.scala.html
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> verifyResourceContains / 200 "app compiles and runs!"

#############################################################################################################################################
# Invalid twirl template (parsing index.scala.html file is OK, but compiling target/scala-*/twirl/main/views/html/index.template.scala fails)
# Actually this tests if the sourcePositionMappers set up by sbt-twirl is called and works correctly
#############################################################################################################################################
$ copy-file app/views/index.scala.html index.scala.html.good
$ copy-file index.scala.html-2.bad app/views/index.scala.html
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> makeRequestAndRecordResponseBody / twirl-fail-2.txt
> checkLinesPartially twirl-fail-2.txt target/twirl-fail-2.txt
> checkLinesPartiallyNotContain blacklist.txt target/twirl-fail-2.txt
$ copy-file index.scala.html.good app/views/index.scala.html
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> verifyResourceContains / 200 "app compiles and runs!"

##########################
# Injected component fails
##########################
$ copy-file app/modules/SomeComponent.java SomeComponent.java.good
$ copy-file SomeComponent.java.bad app/modules/SomeComponent.java
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> makeRequestAndRecordResponseBody / component-fail.txt
> checkLinesPartially component-fail.txt target/component-fail.txt
> checkLinesPartiallyNotContain blacklist.txt target/component-fail.txt
$ copy-file SomeComponent.java.good app/modules/SomeComponent.java
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> verifyResourceContains / 200 "app compiles and runs!"

###################
# Compilation error
###################
$ copy-file app/controllers/HomeController.java HomeController.java.good
$ copy-file HomeController.java.bad app/controllers/HomeController.java
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> makeRequestAndRecordResponseBody / compilation-fail.txt
> checkLinesPartially compilation-fail.txt target/compilation-fail.txt
> checkLinesPartiallyNotContain blacklist.txt target/compilation-fail.txt
$ copy-file HomeController.java.good app/controllers/HomeController.java
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> verifyResourceContains / 200 "app compiles and runs!"

##################################
# Compilation error in sub project
##################################
$ copy-file modules/sub-project-inside/src/main/scala/Foo.java Foo.java.good
$ copy-file Foo.java.bad modules/sub-project-inside/src/main/scala/Foo.java
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> makeRequestAndRecordResponseBody / sub-project-inside-compilation-fail.txt
> checkLinesPartially sub-project-inside-compilation-fail.txt target/sub-project-inside-compilation-fail.txt
> checkLinesPartiallyNotContain blacklist.txt target/sub-project-inside-compilation-fail.txt
$ copy-file Foo.java.good modules/sub-project-inside/src/main/scala/Foo.java
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> verifyResourceContains / 200 "app compiles and runs!"

##############################################################################
# Compilation error in sub project that is located outside of the root project
##############################################################################
$ copy-file ../dev-mode-compile-and-config-error-source-sub-project-outside/src/main/scala/Bar.java Bar.java.good
$ copy-file Bar.java.bad ../dev-mode-compile-and-config-error-source-sub-project-outside/src/main/scala/Bar.java
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> makeRequestAndRecordResponseBody / sub-project-outside-compilation-fail.txt
> checkLinesPartially sub-project-outside-compilation-fail.txt target/sub-project-outside-compilation-fail.txt
> checkLinesPartiallyNotContain blacklist.txt target/sub-project-outside-compilation-fail.txt
$ copy-file Bar.java.good ../dev-mode-compile-and-config-error-source-sub-project-outside/src/main/scala/Bar.java
# Give CI/docker/Java thread enough time to detect file change
$ sleep 1200
> verifyResourceContains / 200 "app compiles and runs!"

> playStop

# Clean up the outside subproject
$ delete ../dev-mode-compile-and-config-error-source-sub-project-outside
