コード例 #1
0
        void RunManagedTests(ManagedTestInfo test, string test_destination = "", bool debug = true, string single_test = null, bool forceSpaces = false, string additionalArgs = "")
        {
            var tmpdir        = Cache.CreateTemporaryDirectory();
            var configuration = debug ? "Debug" : "Release";
            var dll_path      = Path.Combine(XcodeProjectGenerator.TestsRootDirectory, "managed", test.Dlldir, "bin", configuration, test.Dllname);

            // This will build all the managed.dll variants, which is easier than calculating the relative path _as the makefile sees it_ to pass as the target.
            Asserts.RunProcess("make", $"all CONFIG={configuration} -C {Utils.Quote (Path.Combine (XcodeProjectGenerator.TestsRootDirectory, "managed"))}", "build " + Path.GetFileName(dll_path));

            if (forceSpaces)
            {
                string dll_folder = Path.GetDirectoryName(dll_path);
                Directory.CreateDirectory(Path.Combine(dll_folder, "with spaces"));
                string dll_path_with_spaces = Path.Combine(dll_folder, "with spaces", Path.GetFileName(dll_path));
                File.Copy(dll_path, dll_path_with_spaces, true);
                dll_path = dll_path_with_spaces;
            }

            var outdir      = tmpdir + "/out";
            var projectName = "foo";
            var args        = new List <string> ();

            if (debug)
            {
                args.Add("--debug");
            }
            args.Add(dll_path);
            args.Add("-c");
            args.Add($"--outdir={outdir}");
            args.Add("--target=framework");
            args.Add($"--platform={test.Platform}");
            args.Add($"--abi={test.Abi}");
            if (test.AdditionalGeneratorArgs != null)
            {
                args.Add(test.AdditionalGeneratorArgs);
            }

            Asserts.Generate("generate", args.ToArray());

            var framework_path   = Path.Combine(outdir, Path.GetFileNameWithoutExtension(dll_path) + ".framework");
            var projectDirectory = XcodeProjectGenerator.Generate(test.Platform, tmpdir, projectName, framework_path, defines: test.Defines.ToArray());

            string output;
            var    builddir = Path.Combine(tmpdir, "xcode-build-dir");
            string testName = single_test != null ? $"-only-testing:{single_test}" : "";

            Asserts.RunProcess("xcodebuild", $"test -project {Utils.Quote (projectDirectory)} -scheme Tests {test_destination} {testName} CONFIGURATION_BUILD_DIR={Utils.Quote (builddir)}", out output, "run xcode tests");
            // assert the number of tests passed, so that we can be sure we actually ran all the tests. Otherwise it's very easy to ignore when a bug is causing tests to not be built.
            if (single_test == null)
            {
                Assert.That(output, Does.Match($"Test Suite 'All tests' passed at .*\n\t Executed {test.ManagedTestCount} tests, with 0 failures"), "test count");
            }
            else
            {
                Assert.That(output, Does.Match($"Test Suite 'Selected tests' passed at .*\n\t Executed 1 test, with 0 failures"), "test count");
            }
        }
コード例 #2
0
        void RunManagedTests(Platform platform, string test_destination = "", bool debug = true)
        {
            string        dllname;
            string        dlldir;
            string        abi;
            List <string> defines              = new List <string> ();
            var           managedTestCount     = CountTests(Path.Combine(XcodeProjectGenerator.TestsRootDirectory, "objc-cli/libmanaged/Tests/Tests.m"));
            var           xamariniOSTestCount  = CountTests(Path.Combine(XcodeProjectGenerator.TestsRootDirectory, "objcgentest/xcodetemplate/ios/test/iosTests.m"));
            var           xamarinMacTestCount  = CountTests(Path.Combine(XcodeProjectGenerator.TestsRootDirectory, "objcgentest/xcodetemplate/macos/test/macTests.m"));
            var           xamarintvOSTestCount = CountTests(Path.Combine(XcodeProjectGenerator.TestsRootDirectory, "objcgentest/xcodetemplate/tvos/test/tvosTests.m"));

            switch (platform)
            {
            case Platform.macOSFull:
                dlldir  = "macos-full";
                dllname = "managed-macos-full.dll";
                defines.Add("XAMARIN_MAC=1");
                defines.Add("XAMARIN_MAC_FULL=1");
                abi = "x86_64";                 // FIXME: fat XM apps not supported yet
                managedTestCount += xamarinMacTestCount;
                break;

            case Platform.macOSSystem:
                dlldir  = "macos-system";
                dllname = "managed-macos-system.dll";
                defines.Add("XAMARIN_MAC=1");
                defines.Add("XAMARIN_MAC_SYSTEM=1");
                abi = "x86_64";                 // FIXME: fat XM apps not supported yet
                managedTestCount += xamarinMacTestCount;
                break;

            case Platform.macOSModern:
                dlldir  = "macos-modern";
                dllname = "managed-macos-modern.dll";
                defines.Add("XAMARIN_MAC=1");
                defines.Add("XAMARIN_MAC_MODERN=1");
                abi = "x86_64";                 // FIXME: fat XM apps not supported yet
                managedTestCount += xamarinMacTestCount;
                break;

            case Platform.macOS:
                dlldir  = "generic";
                dllname = "managed.dll";
                abi     = "i386,x86_64";
                break;

            case Platform.iOS:
                dlldir  = "ios";
                dllname = "managed-ios.dll";
                defines.Add("XAMARIN_IOS=1");
                abi = "armv7,arm64,i386,x86_64";
                managedTestCount += xamariniOSTestCount;
                break;

            case Platform.tvOS:
                dlldir  = "tvos";
                dllname = "managed-tvos.dll";
                defines.Add("XAMARIN_TVOS=1");
                abi = "arm64,x86_64";
                managedTestCount += xamarintvOSTestCount;
                break;

            default:
                throw new NotImplementedException();
            }
            defines.Add("TEST_FRAMEWORK=1");

            var tmpdir        = Cache.CreateTemporaryDirectory();
            var configuration = debug ? "Debug" : "Release";
            var dll_path      = Path.Combine(XcodeProjectGenerator.TestsRootDirectory, "managed", dlldir, "bin", configuration, dllname);

            // This will build all the managed.dll variants, which is easier than calculating the relative path _as the makefile sees it_ to pass as the target.
            Asserts.RunProcess("make", $"all CONFIG={configuration} -C {Embedder.Quote (Path.Combine (XcodeProjectGenerator.TestsRootDirectory, "managed"))}", "build " + Path.GetFileName(dll_path));

            var outdir      = tmpdir + "/out";
            var projectName = "foo";
            var args        = new List <string> ();

            if (debug)
            {
                args.Add("--debug");
            }
            args.Add(dll_path);
            args.Add("-c");
            args.Add($"--outdir={outdir}");
            args.Add("--target=framework");
            args.Add($"--platform={platform}");
            args.Add($"--abi={abi}");
            Asserts.Generate("generate", args.ToArray());

            var framework_path   = Path.Combine(outdir, Path.GetFileNameWithoutExtension(dll_path) + ".framework");
            var projectDirectory = XcodeProjectGenerator.Generate(platform, tmpdir, projectName, framework_path, defines: defines.ToArray());

            string output;
            var    builddir = Path.Combine(tmpdir, "xcode-build-dir");

            Asserts.RunProcess("xcodebuild", $"test -project {Embedder.Quote (projectDirectory)} -scheme Tests {test_destination} CONFIGURATION_BUILD_DIR={Embedder.Quote (builddir)}", out output, "run xcode tests");
            // assert the number of tests passed, so that we can be sure we actually ran all the tests. Otherwise it's very easy to ignore when a bug is causing tests to not be built.
            Assert.That(output, Does.Match($"Test Suite 'All tests' passed at .*\n\t Executed {managedTestCount} tests, with 0 failures"), "test count");
        }