classdef tValidateToolchainInfoObject < matlab.unittest.TestCase
%tValidateToolchainInfoObject testpoint that validates the build method and generates 
%errors if any properties are incorrectly defined
%   Uses the validate method from the toolchaininfo object associated to 
%   buildMethod, where buildMethod is a toolchain or template makefile defined
%   in the base workspace as a string.
%   The test fails if this method returns any error.

%   Copyright 2020 The MathWorks, Inc.
    
    
    properties(TestParameter)
        buildMethod = {getBuildMethod};
    end
    
    methods(TestMethodSetup)
        
        function setup(test)
            applyFixture(test, matlab.unittest.fixtures.WorkingFolderFixture);
        end
        
    end
    
    methods(Test)
        
        function buildFromBuildMethod(test, buildMethod)
            % Get toolchaininfo object from buildMethod
            lToolchainInfo = coder.make.internal.resolveToolchainOrTMF(buildMethod);
            test.assumeNotEmpty(lToolchainInfo, 'Build method must have an associated ToolchainInfo');
            
            % Validate toolchain
            
            % The setup callbacks (ShellSetup and MATLABSetup) of the toolchain object are evaluated before validation.
            % The cleanup callbacks (ShellCleanup and MATLABCleanup) of the toolchain object are evaluated after validation.
            % "bypassRegistry" ensures the test will not access the toolchain registry
            verifyEqual(test,lToolchainInfo.validate('bypassRegistry','setup','cleanup'),1);
        end
    end
end
