Home | History | Annotate | Download | only in robolectric-shadows
      1 # Defines a target named $(my_target) for running robolectric tests.
      2 
      3 # Running the tests is done in two stages: we first generate the test output to
      4 # $(my_target_output), which is also added to the dist list, and store the
      5 # return value of running the tests in $(my_target_retval). After that we
      6 # process the output and return value as part of $(my_target). This is needed
      7 # to make sure that we can install the test output even if the tests actually
      8 # fail.
      9 
     10 # Files in which to store the output and return value of the tests.
     11 my_target_xml := $(intermediates)/$(my_filename_stem)-output.xml
     12 my_target_output := $(intermediates)/$(my_filename_stem)-output.txt
     13 my_target_retval := $(intermediates)/$(my_filename_stem)-retval.txt
     14 
     15 # We should always re-run the tests, even if nothing has changed.
     16 .PHONY: $(my_target_output) $(my_target_retval)
     17 # Private variables.
     18 $(my_target_output): PRIVATE_MODULE := $(LOCAL_MODULE)
     19 $(my_target_output): PRIVATE_TESTS := $(my_tests)
     20 $(my_target_output): PRIVATE_JARS := $(my_jars)
     21 $(my_target_output): PRIVATE_JAVA_ARGS := $(my_java_args)
     22 $(my_target_output): PRIVATE_ROBOLECTRIC_PATH := $(my_robolectric_path)
     23 $(my_target_output): PRIVATE_ROBOLECTRIC_SCRIPT_PATH := $(my_robolectric_script_path)
     24 $(my_target_output): PRIVATE_TARGET_MESSAGE := $(my_target_message)
     25 $(my_target_output): PRIVATE_TARGET_OUTPUT := $(my_target_output)
     26 $(my_target_output): PRIVATE_TARGET_RETVAL := $(my_target_retval)
     27 $(my_target_output): PRIVATE_TIMEOUT := $(my_timeout)
     28 $(my_target_output): PRIVATE_XML_OUTPUT_FILE := $(my_target_xml)
     29 # Runs the Robolectric tests and saves the output and return value.
     30 $(my_target_output): $(my_jars)
     31 	@echo "host Robolectric: $(PRIVATE_MODULE)"
     32 	# Run `touch` to always create the output XML file, so the build doesn't break even if the
     33 	# runner failed to create the XML output
     34 	$(hide) touch "$(PRIVATE_XML_OUTPUT_FILE)"
     35 	$(hide) \
     36 	  PRIVATE_INTERMEDIATES="$(dir $@)" \
     37 	  PRIVATE_JARS="$(PRIVATE_JARS)" \
     38 	  PRIVATE_JAVA_ARGS="$(PRIVATE_JAVA_ARGS)" \
     39 	  PRIVATE_ROBOLECTRIC_PATH="$(PRIVATE_ROBOLECTRIC_PATH)" \
     40 	  PRIVATE_ROBOLECTRIC_SCRIPT_PATH="$(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)" \
     41 	  PRIVATE_RUN_INDIVIDUALLY="$(ROBOTEST_RUN_INDIVIDUALLY)" \
     42 	  PRIVATE_TARGET_MESSAGE="$(PRIVATE_TARGET_MESSAGE)" \
     43 	  PRIVATE_TIMEOUT="$(PRIVATE_TIMEOUT)" \
     44 	  PRIVATE_TESTS="$(PRIVATE_TESTS)" \
     45 	  XML_OUTPUT_FILE="$(PRIVATE_XML_OUTPUT_FILE)" \
     46 	  TEST_WORKSPACE="$(PRIVATE_MODULE)" \
     47 	  $(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)/wrapper.sh \
     48 	    "$(PRIVATE_MODULE)" \
     49 	    "$(PRIVATE_TARGET_OUTPUT)" \
     50 	    "$(PRIVATE_TARGET_RETVAL)" \
     51 	    wrap \
     52 	    $(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)/robotest.sh
     53 
     54 $(my_target_xml) $(my_target_retval): $(my_target_output)
     55 
     56 # This does not actually generate a file.
     57 .PHONY: $(my_target)
     58 # Private variables.
     59 $(my_target): PRIVATE_MODULE := $(LOCAL_MODULE)
     60 $(my_target): PRIVATE_TARGET_OUTPUT := $(my_target_output)
     61 $(my_target): PRIVATE_TARGET_RETVAL := $(my_target_retval)
     62 $(my_target): PRIVATE_FAILURE_FATAL := $(my_failure_fatal)
     63 $(my_target): PRIVATE_ROBOLECTRIC_SCRIPT_PATH := $(my_robolectric_script_path)
     64 # Process the output and the return value of the tests. This will fail if the
     65 # return value is non-zero.
     66 $(my_target): $(my_target_output) $(my_target_xml)
     67 	$(hide) \
     68 	  result=0; \
     69 	  $(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)/wrapper.sh \
     70 	    "$(PRIVATE_MODULE)" \
     71 	    "$(PRIVATE_TARGET_OUTPUT)" \
     72 	    "$(PRIVATE_TARGET_RETVAL)" \
     73 	    eval \
     74 	      || result=$$?; \
     75 	  if [ "$(strip $(PRIVATE_FAILURE_FATAL))" = true ]; then \
     76 	    exit "$$result"; \
     77 	  fi
     78 
     79 # Add the output of the tests to the dist list, so that we will include it even
     80 # if the tests fail.
     81 $(call dist-for-goals, $(my_target), \
     82     $(my_target_output):robotests/$(LOCAL_MODULE)-$(notdir $(my_target_output)) \
     83     $(my_target_xml):robotests/$(LOCAL_MODULE)-$(notdir $(my_target_xml)))
     84 
     85 # Clean up local variables.
     86 my_target_output :=
     87 my_target_retval :=
     88 my_target_xml :=
     89 my_filename_stem :=
     90