class TestCLIStart(unittest.TestCase): @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_noop_start(self): test_dir = util.writeTestFiles(util.Test_Trivial_Exe, True) util.writeTestFiles(_nopStartTargetDescription('start-test-target'), test_dir=os.path.join(test_dir, 'yotta_targets', 'start-test-target')) output = util.runCheckCommand(['--target', 'start-test-target', 'build'], test_dir) output = util.runCheckCommand(['--target', 'start-test-target', 'start'], test_dir) self.assertIn('would start source/test-trivial-exe', output) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_native_start(self): test_dir = util.writeTestFiles(util.Test_Trivial_Exe, True) output = util.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir) output = util.runCheckCommand(['--target', util.nativeTarget(), 'start'], test_dir) self.assertIn('[trivial-exe-running]', output) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_notfound_start(self): test_dir = util.writeTestFiles(util.Test_Trivial_Exe, True) target_descr = _nopStartTargetDescription('start-test-target') del target_descr['./scripts/nop.py'] util.writeTestFiles(target_descr, test_dir=os.path.join(test_dir, 'yotta_targets', 'start-test-target')) # in this case, without the script present we expect a failure output = util.runCheckCommand(['--target', 'start-test-target', 'build'], test_dir) stdout, stderr, statuscode = cli.run(['--target', 'start-test-target', 'start'], cwd=test_dir) self.assertNotEqual(statuscode, 0) util.rmRf(test_dir)
class TestCLIYottaVersionSpecs(unittest.TestCase): @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_yottaVersionCheckTooLowBuilding(self): test_dir = util.writeTestFiles(Test_Min_Version_Insufficient) stdout, stderr, statuscode = cli.run( ['--target', util.nativeTarget(), 'build'], cwd=test_dir) self.assertNotEqual(statuscode, 0) self.assertIn('requires yotta version >', stdout + stderr) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_yottaVersionCheckOKBuilding(self): test_dir = util.writeTestFiles(Test_Min_Version_OK) stdout, stderr, statuscode = cli.run( ['--target', util.nativeTarget(), 'build'], cwd=test_dir) self.assertEqual(statuscode, 0) self.assertNotIn('requires yotta version >', stdout + stderr) util.rmRf(test_dir) def test_yottaVersionCheckTooLowInstalling(self): test_dir = util.writeTestFiles(Test_Min_Version_Insufficient) stdout, stderr, statuscode = cli.run( ['--target', 'x86-linux-native', 'install'], cwd=test_dir) self.assertNotEqual(statuscode, 0) self.assertIn('requires yotta version >', stdout + stderr) util.rmRf(test_dir) def test_yottaVersionCheckOKInstalling(self): test_dir = util.writeTestFiles(Test_Min_Version_OK) stdout, stderr, statuscode = cli.run( ['--target', 'x86-linux-native', 'install'], cwd=test_dir) self.assertEqual(statuscode, 0) self.assertNotIn('requires yotta version >', stdout + stderr) util.rmRf(test_dir) def test_yottaVersionTargetCheck(self): test_dir = util.writeTestFiles(Test_Min_Version_Target_Insufficient) stdout, stderr, statuscode = cli.run( ['--target', Test_Min_Version_Target_Name, 'install'], cwd=test_dir) self.assertNotEqual(statuscode, 0) self.assertIn('requires yotta version >', stdout + stderr) util.rmRf(test_dir) def test_unparseableSpec(self): test_dir = util.writeTestFiles(Test_Unparsable_Spec) stdout, stderr, statuscode = cli.run( ['--target', Test_Min_Version_Target_Name, 'install'], cwd=test_dir) self.assertNotEqual(statuscode, 0) self.assertIn('could not parse yotta version spec', stdout + stderr) util.rmRf(test_dir)
class TestCLIDebug(unittest.TestCase): @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_noop_debug(self): test_dir = util.writeTestFiles(util.Test_Trivial_Exe, True) target_dir = os.path.realpath( os.path.join(test_dir, 'yotta_targets', 'debug-test-target')) build_dir = os.path.realpath( os.path.join(test_dir, 'build', 'debug-test-target')) util.writeTestFiles(_nopDebugTargetDescription('debug-test-target'), test_dir=target_dir) output = util.runCheckCommand( ['--target', 'debug-test-target', 'build'], test_dir) output = util.runCheckCommand( ['--target', 'debug-test-target', 'debug'], test_dir) json_output = output[:output.index(JSON_MARKER)] result = json.loads(json_output) self.assertTrue(result is not None) self.assertEqual(len(result['argv']), 3) self.assertEqual(result['argv'][0], 'source/test-trivial-exe') self.assertEqual(result['env']['YOTTA_PROGRAM'], 'source/test-trivial-exe') self.assertEqual(result['argv'][1], build_dir) self.assertEqual(result['env']['YOTTA_BUILD_DIR'], build_dir) self.assertEqual(result['argv'][2], target_dir) self.assertEqual(result['env']['YOTTA_TARGET_DIR'], target_dir) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_notfound_debug(self): test_dir = util.writeTestFiles(util.Test_Trivial_Exe, True) target_descr = _nopDebugTargetDescription('debug-test-target') del target_descr['./scripts/nop.py'] util.writeTestFiles(target_descr, test_dir=os.path.join(test_dir, 'yotta_targets', 'debug-test-target')) # in this case, without the script present we expect a failure output = util.runCheckCommand( ['--target', 'debug-test-target', 'build'], test_dir) stdout, stderr, statuscode = cli.run( ['--target', 'debug-test-target', 'debug'], cwd=test_dir) self.assertNotEqual(statuscode, 0) util.rmRf(test_dir)
(kwargs['test_speed'] == 'fast' and (duration >= 1.5 + kwargs['reporter_waits'])): print(stdout + stderr) print(statuscode) print('duration:', duration) if kwargs['test_passes']: self.assertEqual(statuscode, 0) else: self.assertNotEqual(statuscode, 0) # **no** tests should cause a timeout (Which is set at 4.5 seconds in # the test reporter), + the wait-for duration (+ 1 second slack for # process startup etc.) self.assertTrue(duration < 5.5 + kwargs['reporter_waits']) # if a test isn't slow, then it should run in less than 1 seconds if kwargs['test_speed'] == 'fast': self.assertTrue(duration < 1.5 + kwargs['reporter_waits']) return generatedTestMethod def generateTest(**kwargs): test_name = "test_" + '_'.join([ '%s_%s' % (k, v) for k, v in sorted(kwargs.items(), key=lambda x: x[0])]) test_method = generateTestMethod(**kwargs) test_method.__name__ = test_name setattr(TestCLITestGenerated, test_name, test_method) if util.canBuildNatively(): forAllReporterTests(generateTest) else: print('WARNING: skipping test reporter tests (cannot build natively on this platform)')
class TestCLIUnLink(unittest.TestCase): @classmethod def setUpClass(cls): cls.prefix_dir = tempfile.mkdtemp() os.environ['YOTTA_PREFIX'] = cls.prefix_dir @classmethod def tearDownClass(cls): util.rmRf(cls.prefix_dir) cls.prefix_dir = None def testUnlinkNonexistentModule(self): test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep, True) stdout, stderr, statuscode = cli.run(['-t', Test_Target, '--plain', 'unlink', 'doesnotexist'], cwd=test_module) self.assertNotEqual(statuscode, 0) util.rmRf(test_module) def testUnlinkNonexistentTarget(self): test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep, True) stdout, stderr, statuscode = cli.run(['-t', Test_Target, '--plain', 'unlink-target', 'doesnotexist'], cwd=test_module) self.assertNotEqual(statuscode, 0) util.rmRf(test_module) def testUnlinkNotLinkedModuleGlobally(self): test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep, True) stdout, stderr, statuscode = cli.run(['-t', Test_Target, '--plain', 'unlink'], cwd=test_module) self.assertNotEqual(statuscode, 0) util.rmRf(test_module) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def testUnlinkNotLinkedTargetGlobally(self): test_target = util.writeTestFiles(util.getNativeTargetDescription(), True) stdout, stderr, statuscode = cli.run(['-t', Test_Target, '--plain', 'unlink'], cwd=test_target) self.assertNotEqual(statuscode, 0) util.rmRf(test_target) def testUnlinkModuleGlobally(self): test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep, True) stdout, stderr, statuscode = cli.run(['-t', Test_Target, '--plain', 'link'], cwd=test_module) self.assertEqual(statuscode, 0) stdout, stderr, statuscode = cli.run(['-t', Test_Target, '--plain', 'unlink'], cwd=test_module) self.assertEqual(statuscode, 0) util.rmRf(test_module) def testUnlinkTargetGlobally(self): test_target = util.writeTestFiles(util.getNativeTargetDescription(), True) stdout, stderr, statuscode = cli.run(['-t', Test_Target, '--plain', 'link-target'], cwd=test_target) self.assertEqual(statuscode, 0) stdout, stderr, statuscode = cli.run(['-t', Test_Target, '--plain', 'unlink-target'], cwd=test_target) self.assertEqual(statuscode, 0) util.rmRf(test_target) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def testUnlinkModule(self): linked_in_module = util.writeTestFiles(util.Test_Trivial_Lib, True) test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep, True) stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'link'], cwd=linked_in_module) self.assertEqual(statuscode, 0) stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'link', 'test-trivial-lib'], cwd=test_module) self.assertEqual(statuscode, 0) self.assertTrue(os.path.exists(os.path.join(test_module, 'yotta_modules', 'test-trivial-lib'))) stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'unlink', 'test-trivial-lib'], cwd=test_module) self.assertEqual(statuscode, 0) self.assertTrue(not os.path.exists(os.path.join(test_module, 'yotta_modules', 'test-trivial-lib'))) util.rmRf(test_module) util.rmRf(linked_in_module) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on this platform yet") def testUnlinkTarget(self): linked_in_target = util.writeTestFiles(util.getNativeTargetDescription(), True) test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep_Preinstalled, True) stdout, stderr, statuscode = cli.run(['-t', 'test-native-target', '--plain', 'link-target'], cwd=linked_in_target) self.assertEqual(statuscode, 0) stdout, stderr, statuscode = cli.run(['-t', 'test-native-target', '--plain', 'link-target', 'test-native-target'], cwd=test_module) self.assertEqual(statuscode, 0) self.assertTrue(os.path.exists(os.path.join(test_module, 'yotta_targets', 'test-native-target'))) stdout, stderr, statuscode = cli.run(['-t', 'test-native-target', '--plain', 'unlink-target', 'test-native-target'], cwd=test_module) self.assertEqual(statuscode, 0) self.assertTrue(not os.path.exists(os.path.join(test_module, 'yotta_targets', 'test-native-target'))) util.rmRf(test_module) util.rmRf(linked_in_target)
class TestCLIBuild(unittest.TestCase): @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_buildTrivialLib(self): test_dir = util.writeTestFiles(util.Test_Trivial_Lib) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_buildTrivialExe(self): test_dir = util.writeTestFiles(util.Test_Trivial_Exe) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_buildComplex(self): test_dir = util.writeTestFiles(Test_Complex) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_buildComplexSpaceInPath(self): test_dir = util.writeTestFiles(Test_Complex, True) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_buildTests(self): test_dir = util.writeTestFiles(Test_Tests, True) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'test'], test_dir) self.assertIn('test-a', stdout) self.assertIn('test-c', stdout) self.assertIn('test-d', stdout) self.assertIn('test-e', stdout) self.assertIn('test-f', stdout) self.assertIn('test-g', stdout) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_buildInfo(self): test_dir = util.writeTestFiles(Test_Build_Info, True) # commit all the test files to git so that the VCS build info gets # defined: # (set up the git user env vars so we can run git commit without barfing) util.setupGitUser() subprocess.check_call(['git', 'init', '-q'], cwd=test_dir) subprocess.check_call(['git', 'add', '.'], cwd=test_dir) subprocess.check_call( ['git', 'commit', '-m', 'test build info automated commit', '-q'], cwd=test_dir) self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) build_time = datetime.datetime.utcnow() output = subprocess.check_output([ './build/' + util.nativeTarget().split(',')[0] + '/source/test-trivial-exe' ], cwd=test_dir).decode() self.assertIn('vcs clean: 1', output) # check build timestamp self.assertIn('build timestamp: ', output) build_timestamp_s = re.search('build timestamp: (.*)\n', output) self.assertTrue(build_timestamp_s) build_timestamp_s = build_timestamp_s.group(1) build_time_parsed = datetime.datetime.strptime(build_timestamp_s, '%Y-%m-%d-%H-%M-%S') build_time_skew = build_time_parsed - build_time self.assertTrue(abs(build_time_skew.total_seconds()) < 3) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_extraCMakeBuild(self): test_dir = util.writeTestFiles(util.Test_Extra_CMake_Lib, True) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_customCMakeBuild(self): test_dir = util.writeTestFiles(util.Test_Custom_CMake_Lib, True) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_extraCMakeBuildExe(self): test_dir = util.writeTestFiles(util.Test_Extra_CMake_Exe, True) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_customCMakeBuildExe(self): test_dir = util.writeTestFiles(util.Test_Custom_CMake_Exe, True) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_ignoreCustomCMake(self): test_dir = util.writeTestFiles(Test_Ignore_Custom_Cmake, True) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) self.assertNotIn('should be ignored', stdout) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_customLibDir(self): test_dir = util.writeTestFiles(Test_Custom_Lib_Dir, True) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) self.assertIn('this message should be printed', stdout) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_customLibSubDir(self): test_dir = util.writeTestFiles(Test_Custom_Lib_Sub_Dir, True) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) self.assertIn('this message should be printed', stdout) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_customLibSubSourceDir(self): test_dir = util.writeTestFiles(Test_Custom_Lib_Sub_Source_Dir, True) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) self.assertIn('this message should be printed', stdout) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_customBinDir(self): test_dir = util.writeTestFiles(Test_Custom_Bin_Dir, True) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) self.assertIn('this message should be printed', stdout) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_customBinSubDir(self): test_dir = util.writeTestFiles(Test_Custom_Bin_Sub_Dir, True) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) self.assertIn('this message should be printed', stdout) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_customBinSubSourceDir(self): test_dir = util.writeTestFiles(Test_Custom_Bin_Sub_Source_Dir, True) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) self.assertIn('this message should be printed', stdout) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_libAndBinSpecified(self): test_dir = util.writeTestFiles(Test_Lib_And_Bin) stdout, stderr, statuscode = cli.run( ['--target', util.nativeTarget(), 'build'], cwd=test_dir) self.assertNotEqual(statuscode, 0) self.assertIn( 'Both "lib" and "bin" are specified in module.json: only one is allowed', stdout + stderr) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_libNonExistent(self): test_dir = util.writeTestFiles(Test_Lib_Nonexistent) stdout, stderr, statuscode = cli.run( ['--target', util.nativeTarget(), 'build'], cwd=test_dir) self.assertIn('directory "doesntexist" doesn\'t exist', stdout + stderr) # !!! FIXME: should this error be fatal? # self.assertNotEqual(statuscode, 0) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_binNonExistent(self): test_dir = util.writeTestFiles(Test_Bin_Nonexistent) stdout, stderr, statuscode = cli.run( ['--target', util.nativeTarget(), 'build'], cwd=test_dir) self.assertIn('directory "doesntexist" doesn\'t exist', stdout + stderr) # !!! FIXME: should this error be fatal? # self.assertNotEqual(statuscode, 0) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_misspeltSourceDir1(self): test_dir = util.writeTestFiles(Test_Misspelt_Source_Dir_1) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) self.assertIn("has non-standard source directory name", stdout) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_misspeltSourceDir2(self): test_dir = util.writeTestFiles(Test_Misspelt_Source_Dir_2) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) self.assertIn("has non-standard source directory name", stdout) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_misspeltSourceDirIgnored(self): test_dir = util.writeTestFiles(Test_Ignored_Misspelt_Source_Dir) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) self.assertNotIn("has non-standard source directory name", stdout) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_scriptsPreBuild(self): test_dir = util.writeTestFiles(Test_Scripts_PreBuild) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) self.assertIn("running prebuild", stdout) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_scriptsPostBuild(self): test_dir = util.writeTestFiles(Test_Scripts_PostBuild) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) self.assertIn("running postbuild", stdout) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_scriptsPreGenerate(self): test_dir = util.writeTestFiles(Test_Scripts_PreGenerate) stdout = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) self.assertIn("running pregenerate", stdout) util.rmRf(test_dir) def runCheckCommand(self, args, test_dir): stdout, stderr, statuscode = cli.run(args, cwd=test_dir) if statuscode != 0: print('command failed with status %s' % statuscode) print(stdout) print(stderr) self.assertEqual(statuscode, 0) return stdout + stderr
class TestCLIInstall(unittest.TestCase): @unittest.skipIf(not hasGithubConfig( ), "a github authtoken must be specified for this test (run yotta login, or set YOTTA_GITHUB_AUTHTOKEN)" ) def test_installRegistryRef(self): test_dir = tempfile.mkdtemp() stdout = self.runCheckCommand( ['--target', Test_Target, 'install', Test_Name], test_dir) rmRf(test_dir) @unittest.skipIf(not hasGithubConfig( ), "a github authtoken must be specified for this test (run yotta login, or set YOTTA_GITHUB_AUTHTOKEN)" ) def test_installGithubRef(self): test_dir = tempfile.mkdtemp() stdout = self.runCheckCommand( ['--target', Test_Target, 'install', Test_Github_Name], test_dir) rmRf(test_dir) @unittest.skipIf(not hasGithubConfig( ), "a github authtoken must be specified for this test (run yotta login, or set YOTTA_GITHUB_AUTHTOKEN)" ) def test_installDeps(self): test_dir = tempfile.mkdtemp() with open(os.path.join(test_dir, 'module.json'), 'w') as f: f.write(Test_Module_JSON) stdout = self.runCheckCommand(['--target', Test_Target, 'install'], test_dir) # also sanity-check listing: stdout = self.runCheckCommand(['--target', Test_Target, 'ls'], test_dir) self.assertIn('testmod', stdout) self.assertIn('other-testing-dummy', stdout) self.assertIn('test-testing-dummy', stdout) self.assertIn('test-target-dep', stdout) stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'], test_dir) self.assertIn('testmod', stdout) self.assertIn('other-testing-dummy', stdout) self.assertIn('test-testing-dummy', stdout) self.assertIn('test-target-dep', stdout) # and test install <modulename> stdout = self.runCheckCommand( ['--target', Test_Target, 'install', 'hg-access-testing'], test_dir) stdout = self.runCheckCommand(['--target', Test_Target, 'ls'], test_dir) self.assertIn('hg-access-testing', stdout) rmRf(test_dir) @unittest.skipIf(not hasGithubConfig( ), "a github authtoken must be specified for this test (run yotta login, or set YOTTA_GITHUB_AUTHTOKEN)" ) def test_installAllTestDeps(self): test_dir = tempfile.mkdtemp() with open(os.path.join(test_dir, 'module.json'), 'w') as f: f.write(Test_Module_JSON) stdout = self.runCheckCommand( ['--target', Test_Target, 'install', '--test-dependencies', 'all'], test_dir) # also sanity-check listing: stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'], test_dir) self.assertIn('testmod', stdout) self.assertIn('other-testing-dummy', stdout) self.assertIn('test-testing-dummy', stdout) self.assertIn('test-target-dep', stdout) self.assertNotIn('missing', stdout) rmRf(test_dir) @unittest.skipIf(not hasGithubConfig( ), "a github authtoken must be specified for this test (run yotta login, or set YOTTA_GITHUB_AUTHTOKEN)" ) def test_installNoTestDeps(self): test_dir = tempfile.mkdtemp() with open(os.path.join(test_dir, 'module.json'), 'w') as f: f.write(Test_Module_JSON) stdout = self.runCheckCommand([ '--target', Test_Target, 'install', '--test-dependencies', 'none' ], test_dir) # also sanity-check listing: stdout = self.runCheckCommand(['--target', Test_Target, 'ls'], test_dir) self.assertIn('testmod', stdout) self.assertIn('other-testing-dummy', stdout) self.assertTrue(re.search('test-testing-dummy.*missing', stdout)) self.assertTrue(re.search('test-target-dep.*missing', stdout)) stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'], test_dir) self.assertIn('testmod', stdout) self.assertIn('other-testing-dummy', stdout) self.assertTrue(re.search('test-testing-dummy.*missing', stdout)) self.assertTrue(re.search('test-target-dep.*missing', stdout)) rmRf(test_dir) @unittest.skipIf(not hasGithubConfig( ), "a github authtoken must be specified for this test (run yotta login, or set YOTTA_GITHUB_AUTHTOKEN)" ) def test_installComplexDeps(self): test_dir = tempfile.mkdtemp() with open(os.path.join(test_dir, 'module.json'), 'w') as f: f.write(Test_Complex_Module_JSON) stdout = self.runCheckCommand(['--target', Test_Target, 'install'], test_dir) # also sanity-check listing: stdout = self.runCheckCommand(['--target', Test_Target, 'ls'], test_dir) self.assertIn('test-testdep-b', stdout) self.assertIn('test-testdep-c', stdout) self.assertIn('test-testdep-d', stdout) self.assertIn('test-testdep-e', stdout) self.assertIn('test-testdep-f', stdout) self.assertIn('test-testdep-h', stdout) self.assertNotIn('test-testdep-g', stdout) self.assertNotIn('test-testdep-i', stdout) self.assertNotIn('test-testdep-j', stdout) self.assertNotIn('test-testdep-k', stdout) self.assertNotIn('missing', stdout) stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'], test_dir) self.assertIn('test-testdep-b', stdout) self.assertIn('test-testdep-c', stdout) self.assertIn('test-testdep-d', stdout) self.assertIn('test-testdep-e', stdout) self.assertIn('test-testdep-f', stdout) self.assertIn('test-testdep-h', stdout) self.assertTrue(re.search('test-testdep-nodeps.*missing', stdout)) self.assertTrue(re.search('test-testdep-i.*missing', stdout)) self.assertTrue(re.search('test-testdep-g.*missing', stdout)) self.assertNotIn('test-testdep-j', stdout) self.assertNotIn('test-testdep-k', stdout) # test update stdout = self.runCheckCommand(['--target', Test_Target, 'up'], test_dir) rmRf(test_dir) @unittest.skipIf(not hasGithubConfig( ), "a github authtoken must be specified for this test (run yotta login, or set YOTTA_GITHUB_AUTHTOKEN)" ) def test_installAllComplexTestDeps(self): test_dir = tempfile.mkdtemp() with open(os.path.join(test_dir, 'module.json'), 'w') as f: f.write(Test_Complex_Module_JSON) stdout = self.runCheckCommand( ['--target', Test_Target, 'install', '--test-dependencies', 'all'], test_dir) # also sanity-check listing: stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'], test_dir) self.assertIn('test-testdep-b', stdout) self.assertIn('test-testdep-c', stdout) self.assertIn('test-testdep-d', stdout) self.assertIn('test-testdep-e', stdout) self.assertIn('test-testdep-f', stdout) self.assertIn('test-testdep-g', stdout) self.assertIn('test-testdep-h', stdout) self.assertIn('test-testdep-i', stdout) self.assertNotIn('test-testdep-j', stdout) self.assertNotIn('test-testdep-k', stdout) self.assertNotIn('missing', stdout) rmRf(test_dir) @unittest.skipIf(not hasGithubConfig( ), "a github authtoken must be specified for this test (run yotta login, or set YOTTA_GITHUB_AUTHTOKEN)" ) def test_installNoComplexTestDeps(self): test_dir = tempfile.mkdtemp() with open(os.path.join(test_dir, 'module.json'), 'w') as f: f.write(Test_Complex_Module_JSON) stdout = self.runCheckCommand([ '--target', Test_Target, 'install', '--test-dependencies', 'none' ], test_dir) # also sanity-check listing: stdout = self.runCheckCommand(['--target', Test_Target, 'ls'], test_dir) self.assertIn('test-testdep-b', stdout) self.assertIn('test-testdep-c', stdout) self.assertIn('test-testdep-d', stdout) # e should be installed because it is both a test dep and non-test dep: # maybe it shouldn't show up in the listing without -a though? self.assertIn('test-testdep-e', stdout) self.assertIn('test-testdep-f', stdout) self.assertIn('test-testdep-h', stdout) self.assertNotIn('test-testdep-g', stdout) self.assertNotIn('test-testdep-i', stdout) self.assertNotIn('test-testdep-j', stdout) self.assertNotIn('test-testdep-k', stdout) self.assertNotIn('missing', stdout) stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'], test_dir) self.assertIn('test-testdep-b', stdout) self.assertIn('test-testdep-c', stdout) self.assertIn('test-testdep-d', stdout) self.assertIn('test-testdep-e', stdout) self.assertIn('test-testdep-f', stdout) self.assertIn('test-testdep-h', stdout) self.assertTrue(re.search('test-testdep-nodeps.*missing', stdout)) self.assertTrue(re.search('test-testdep-i.*missing', stdout)) self.assertTrue(re.search('test-testdep-g.*missing', stdout)) self.assertNotIn('test-testdep-j', stdout) self.assertNotIn('test-testdep-k', stdout) rmRf(test_dir) @unittest.skipIf(not hasGithubConfig( ), "a github authtoken must be specified for this test (run yotta login, or set YOTTA_GITHUB_AUTHTOKEN)" ) def test_remove(self): test_dir = tempfile.mkdtemp() with open(os.path.join(test_dir, 'module.json'), 'w') as f: f.write(Test_Module_JSON) stdout = self.runCheckCommand(['--target', Test_Target, 'install'], test_dir) self.assertTrue( os.path.exists( os.path.join(test_dir, 'yotta_modules', 'testing-dummy'))) self.runCheckCommand(['remove', 'testing-dummy'], test_dir) self.assertFalse( os.path.exists( os.path.join(test_dir, 'yotta_modules', 'testing-dummy'))) stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'], test_dir) self.assertIn('testing-dummy', stdout) rmRf(test_dir) @unittest.skipIf(not hasGithubConfig( ), "a github authtoken must be specified for this test (run yotta login, or set YOTTA_GITHUB_AUTHTOKEN)" ) def test_uninstall(self): test_dir = tempfile.mkdtemp() with open(os.path.join(test_dir, 'module.json'), 'w') as f: f.write(Test_Module_JSON) stdout = self.runCheckCommand(['--target', Test_Target, 'install'], test_dir) self.assertTrue( os.path.exists( os.path.join(test_dir, 'yotta_modules', 'testing-dummy'))) self.runCheckCommand(['uninstall', 'testing-dummy'], test_dir) self.assertFalse( os.path.exists( os.path.join(test_dir, 'yotta_modules', 'testing-dummy'))) stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'], test_dir) self.assertNotIn(' testing-dummy', stdout) rmRf(test_dir) @unittest.skipIf(not hasGithubConfig( ), "a github authtoken must be specified for this test (run yotta login, or set YOTTA_GITHUB_AUTHTOKEN)" ) def test_uninstallNonExistent(self): test_dir = tempfile.mkdtemp() with open(os.path.join(test_dir, 'module.json'), 'w') as f: f.write(Test_Module_JSON) stdout = self.runCheckCommand(['--target', Test_Target, 'install'], test_dir) self.assertTrue( os.path.exists( os.path.join(test_dir, 'yotta_modules', 'testing-dummy'))) stdout, stderr, statuscode = cli.run(['uninstall', 'nonexistent'], cwd=test_dir) self.assertNotEqual(statuscode, 0) rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "cannot build natively") def test_postInstall_topLevel(self): test_dir = util.writeTestFiles({}) self.runCheckCommand( ['--target', util.nativeTarget(), 'install', 'test-post-install'], test_dir) output = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], os.path.join(test_dir, 'test-post-install')) self.assertIn('post-install generated file compiled', output) self.assertIn('post-install generated header file included', output) self.assertIn('generated .cmake file included', output) @unittest.skipIf(not util.canBuildNatively(), "cannot build natively") def test_postInstall_dependency(self): test_dir = util.writeTestFiles({ 'module.json': '''{ "name": "test-postinstall", "version": "1.0.0", "license": "Apache-2.0", "dependencies": { "test-post-install": "*" }, "bin":"./source" }''', 'source/lib.c': ''' #include <stdio.h> #include "test-post-install/generated.h" int main(){ printf("generated return val=%d\\n", postInstallGenerated()); return 0; } ''' }) output = self.runCheckCommand( ['--target', util.nativeTarget(), 'build'], test_dir) self.assertIn('post-install generated file compiled', output) self.assertIn('post-install generated header file included', output) self.assertIn('generated .cmake file included', output) def runCheckCommand(self, args, test_dir): stdout, stderr, statuscode = cli.run(args, cwd=test_dir) #print stdout self.assertEqual(statuscode, 0) return stdout + stderr
class TestCLITest(unittest.TestCase): @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_tests(self): test_dir = util.writeTestFiles(Test_Tests, True) output = self.runCheckCommand( ['--target', systemDefaultTarget(), 'build'], test_dir) output = self.runCheckCommand( ['--target', systemDefaultTarget(), 'test'], test_dir) self.assertIn('test-a passed', output) self.assertIn('test-c passed', output) self.assertIn('test-d passed', output) self.assertIn('test-e passed', output) self.assertIn('test-f passed', output) self.assertIn('test-g passed', output) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_testOutputFilterPassing(self): test_dir = util.writeTestFiles(Test_Fitler_Pass, True) stdout = self.runCheckCommand( ['--target', systemDefaultTarget(), 'test'], test_dir) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_testOutputFilterFailing(self): test_dir = util.writeTestFiles(Test_Fitler_Fail, True) stdout, stderr, statuscode = cli.run( ['--target', systemDefaultTarget(), 'test'], cwd=test_dir) if statuscode == 0: print(stdout) print(stderr) self.assertIn('test-a failed', '%s %s' % (stdout, stderr)) self.assertIn('test-c failed', '%s %s' % (stdout, stderr)) self.assertIn('test-d failed', '%s %s' % (stdout, stderr)) self.assertIn('test-e failed', '%s %s' % (stdout, stderr)) self.assertIn('test-f failed', '%s %s' % (stdout, stderr)) self.assertIn('test-g failed', '%s %s' % (stdout, stderr)) self.assertNotEqual(statuscode, 0) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_testOutputFilterNotFound(self): test_dir = util.writeTestFiles(Test_Fitler_NotFound, True) stdout, stderr, statuscode = cli.run( ['--target', systemDefaultTarget(), 'test'], cwd=test_dir) if statuscode == 0: print(stdout) print(stderr) self.assertNotEqual(statuscode, 0) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_testCustomCMake(self): test_dir = util.writeTestFiles(util.Test_Test_Custom_CMake, True) output = self.runCheckCommand( ['--target', systemDefaultTarget(), 'test'], test_dir) self.assertIn('test-trivial-lib-maintest passed', output) util.rmRf(test_dir) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on windows yet") def test_testAdditionalCMake(self): test_dir = util.writeTestFiles(util.Test_Test_Extra_CMake, True) output = self.runCheckCommand( ['--target', systemDefaultTarget(), 'test'], test_dir) self.assertIn('test-trivial-lib-test-main passed', output) util.rmRf(test_dir) def runCheckCommand(self, args, test_dir): stdout, stderr, statuscode = cli.run(args, cwd=test_dir) if statuscode != 0: print('command failed with status %s' % statuscode) print(stdout) print(stderr) self.assertEqual(statuscode, 0) return '%s %s' % (stdout, stderr)
else: self.assertNotEqual(statuscode, 0) # **no** tests should cause a timeout (Which is set at 4.5 seconds in # the test reporter), + the wait-for duration (+ 1 second slack for # process startup etc.) self.assertTrue(duration < 5.5 + kwargs['reporter_waits']) # if a test isn't slow, then it should run in less than 1 seconds if kwargs['test_speed'] == 'fast': self.assertTrue(duration < 1.5 + kwargs['reporter_waits']) return generatedTestMethod def generateTest(**kwargs): test_name = "test_" + '_'.join([ '%s_%s' % (k, v) for k, v in sorted(kwargs.items(), key=lambda x: x[0]) ]) test_method = generateTestMethod(**kwargs) test_method.__name__ = test_name setattr(TestCLITestGenerated, test_name, test_method) if util.canBuildNatively(): forAllReporterTests(generateTest) else: print( 'WARNING: skipping test reporter tests (cannot build natively on this platform)' )
class TestCLILink(unittest.TestCase): @classmethod def setUpClass(cls): cls.prefix_dir = tempfile.mkdtemp() os.environ['YOTTA_PREFIX'] = cls.prefix_dir @classmethod def tearDownClass(cls): util.rmRf(cls.prefix_dir) cls.prefix_dir = None def testLink(self): linked_in_module = util.writeTestFiles(util.Test_Trivial_Lib, True) stdout, stderr, statuscode = cli.run( ['-t', Test_Target, '--plain', 'link'], cwd=linked_in_module) self.assertEqual(statuscode, 0) self.assertTrue( os.path.exists( os.path.join(globalInstallDirectory(), 'test-trivial-lib'))) test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep, True) stdout, stderr, statuscode = cli.run( ['-t', Test_Target, '--plain', 'list'], cwd=test_module) self.assertIn('missing', stdout + stderr) stdout, stderr, statuscode = cli.run( ['-t', Test_Target, '--plain', 'link', 'test-trivial-lib'], cwd=test_module) self.assertEqual(statuscode, 0) self.assertNotIn('broken', stdout + stderr) stdout, stderr, statuscode = cli.run( ['-t', Test_Target, '--plain', 'list'], cwd=test_module) self.assertNotIn('missing', stdout + stderr) util.rmRf(test_module) util.rmRf(linked_in_module) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on this platform yet") def testLinkedBuild(self): linked_in_module = util.writeTestFiles(util.Test_Trivial_Lib, True) test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep, True) stdout, stderr, statuscode = cli.run( ['-t', util.nativeTarget(), '--plain', 'link'], cwd=linked_in_module) self.assertEqual(statuscode, 0) stdout, stderr, statuscode = cli.run( ['-t', util.nativeTarget(), '--plain', 'link', 'test-trivial-lib'], cwd=test_module) self.assertEqual(statuscode, 0) stdout, stderr, statuscode = cli.run( ['-t', util.nativeTarget(), '--plain', 'build'], cwd=test_module) self.assertEqual(statuscode, 0) util.rmRf(test_module) util.rmRf(linked_in_module) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on this platform yet") def testLinkedReBuild(self): # test that changing which module is linked triggers a re-build linked_in_module_1 = util.writeTestFiles(util.Test_Trivial_Lib, True) linked_in_module_2 = util.writeTestFiles(util.Test_Trivial_Lib, True) test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep, True) stdout, stderr, statuscode = cli.run( ['-t', util.nativeTarget(), '--plain', 'link'], cwd=linked_in_module_1) self.assertEqual(statuscode, 0) stdout, stderr, statuscode = cli.run( ['-t', util.nativeTarget(), '--plain', 'link', 'test-trivial-lib'], cwd=test_module) self.assertEqual(statuscode, 0) stdout, stderr, statuscode = cli.run( ['-t', util.nativeTarget(), '--plain', 'build'], cwd=test_module) self.assertEqual(statuscode, 0) # check that rebuild is no-op stdout, stderr, statuscode = cli.run( ['-t', util.nativeTarget(), '--plain', 'build'], cwd=test_module) self.assertIn('no work to do', stdout + stderr) self.assertEqual(statuscode, 0) stdout, stderr, statuscode = cli.run( ['-t', util.nativeTarget(), '--plain', 'link'], cwd=linked_in_module_2) self.assertEqual(statuscode, 0) stdout, stderr, statuscode = cli.run( ['-t', util.nativeTarget(), '--plain', 'build'], cwd=test_module) self.assertNotIn('no work to do', stdout + stderr) self.assertEqual(statuscode, 0) util.rmRf(test_module) util.rmRf(linked_in_module_1) util.rmRf(linked_in_module_2) @unittest.skipIf(not util.canBuildNatively(), "can't build natively on this platform yet") def testTargetLinkedBuild(self): linked_in_target = util.writeTestFiles( util.getNativeTargetDescription(), True) test_module = util.writeTestFiles( util.Test_Testing_Trivial_Lib_Dep_Preinstalled, True) stdout, stderr, statuscode = cli.run( ['-t', 'test-native-target', '--plain', 'link-target'], cwd=linked_in_target) self.assertEqual(statuscode, 0) stdout, stderr, statuscode = cli.run([ '-t', 'test-native-target', '--plain', 'link-target', 'test-native-target' ], cwd=test_module) self.assertEqual(statuscode, 0) stdout, stderr, statuscode = cli.run( ['-t', 'test-native-target', '--plain', 'build'], cwd=test_module) self.assertEqual(statuscode, 0) util.rmRf(test_module) util.rmRf(linked_in_target)