@@ -1949,75 +1949,61 @@ def test_(toolchain=None, mcu=None, compile_list=False, run_list=False, compile_
1949
1949
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
1950
1950
orig_path = os .getcwd ()
1951
1951
1952
- # Change directories to the program root to use mbed OS tools
1952
+ target = program .get_mcu (mcu )
1953
+ tchain = program .get_toolchain (toolchain )
1954
+ macros = program .get_macros ()
1955
+ tools_dir = program .get_tools ()
1956
+ build_and_run_tests = not compile_list and not run_list and not compile_only and not run_only
1957
+ relative_orig_path = os .path .relpath (orig_path , program .path )
1958
+
1959
+ env = os .environ .copy ()
1960
+ env ['PYTHONPATH' ] = os .path .abspath (program .path )
1961
+
1953
1962
with cd (program .path ):
1954
- target = program .get_mcu (mcu )
1955
- tchain = program .get_toolchain (toolchain )
1956
- macros = program .get_macros ()
1957
- tools_dir = program .get_tools ()
1958
-
1959
- env = os .environ .copy ()
1960
- env ['PYTHONPATH' ] = os .path .abspath (program .path )
1961
-
1962
1963
# Setup the source path if not specified
1963
1964
if not source or len (source ) == 0 :
1964
- source = [os . path . relpath ( program .path , orig_path ) ]
1965
+ source = [program .path ]
1965
1966
1966
1967
# Setup the build path if not specified
1967
1968
if not build :
1968
- build = os .path .join (os . path . relpath ( program .path , orig_path ) , '.build/tests' , target , tchain )
1969
-
1969
+ build = os .path .join (program .path , '.build/tests' , target , tchain )
1970
+
1970
1971
# Create the path to the test spec file
1971
1972
test_spec = os .path .join (build , 'test_spec.json' )
1972
-
1973
- # Determine if building and running tests
1974
- build_and_run_tests = not compile_list and not run_list and not compile_only and not run_only
1975
-
1976
- if compile_only or build_and_run_tests :
1977
- cmd = ['python' , '-u' , os .path .join (tools_dir , 'test.py' )]
1978
- cmd += list (chain .from_iterable (izip (repeat ('-D' ), macros )))
1979
- cmd += ['-t' , tchain , '-m' , target ]
1980
- cmd += (['-c' ] if clean else [])
1981
- cmd += list (chain .from_iterable (izip (repeat ('--source' ), source )))
1982
- cmd += ['--build' , build ]
1983
- cmd += ['--test-spec' , test_spec ]
1984
- cmd += (['-n' , tests_by_name ] if tests_by_name else [])
1985
- cmd += (['-v' ] if very_verbose else [])
1986
-
1987
- try :
1988
- popen (cmd + args , env = env )
1989
- except ProcessException :
1990
- error ('Failed to run the test compiling script' )
1991
-
1992
- if run_only or build_and_run_tests :
1993
- cmd = ['mbedgt' , '--test-spec' , test_spec ]
1994
- cmd += (['-n' , tests_by_name ] if tests_by_name else [])
1995
- cmd += (['-V' ] if verbose else [])
1996
-
1997
- try :
1998
- popen (cmd + args , env = env )
1999
- except ProcessException :
2000
- error ('Failed to run test runner' )
2001
-
1973
+
2002
1974
if compile_list :
2003
- cmd = ['python' , '-u' , os .path .join (tools_dir , 'test.py' ), '--list' ]
2004
- cmd += (['-n' , tests_by_name ] if tests_by_name else [])
2005
- cmd += (['-v' ] if very_verbose else [])
2006
-
2007
- try :
2008
- popen (cmd + args , env = env )
2009
- except ProcessException :
2010
- error ('Failed to run buildable tests listing script' )
2011
-
1975
+ popen (['python' , '-u' , os .path .join (tools_dir , 'test.py' ), '--list' ]
1976
+ + (['-n' , tests_by_name ] if tests_by_name else [])
1977
+ + (['-v' ] if very_verbose else [])
1978
+ + args ,
1979
+ env = env )
1980
+
1981
+ if compile_only or build_and_run_tests :
1982
+ popen (['python' , '-u' , os .path .join (tools_dir , 'test.py' )]
1983
+ + list (chain .from_iterable (izip (repeat ('-D' ), macros )))
1984
+ + ['-t' , tchain , '-m' , target ]
1985
+ + (['-c' ] if clean else [])
1986
+ + list (chain .from_iterable (izip (repeat ('--source' ), source )))
1987
+ + ['--build' , build ]
1988
+ + ['--test-spec' , test_spec ]
1989
+ + (['-n' , tests_by_name ] if tests_by_name else [])
1990
+ + (['-v' ] if very_verbose else [])
1991
+ + args ,
1992
+ env = env )
1993
+
2012
1994
if run_list :
2013
- cmd = ['mbedgt' , '--test-spec' , test_spec , '--list' ]
2014
- cmd += (['-n' , tests_by_name ] if tests_by_name else [])
2015
- cmd += (['-V' ] if verbose else [])
2016
-
2017
- try :
2018
- popen (cmd + args , env = env )
2019
- except ProcessException :
2020
- error ('Failed to run test runner' )
1995
+ popen (['mbedgt' , '--test-spec' , test_spec , '--list' ]
1996
+ + (['-n' , tests_by_name ] if tests_by_name else [])
1997
+ + (['-V' ] if very_verbose else [])
1998
+ + args ,
1999
+ env = env )
2000
+
2001
+ if run_only or build_and_run_tests :
2002
+ popen (['mbedgt' , '--test-spec' , test_spec ]
2003
+ + (['-n' , tests_by_name ] if tests_by_name else [])
2004
+ + (['-V' ] if very_verbose else [])
2005
+ + args ,
2006
+ env = env )
2021
2007
2022
2008
2023
2009
# Export command
0 commit comments