Skip to content

Commit b72f305

Browse files
committed
update tests
1 parent 6103f34 commit b72f305

20 files changed

+71
-42
lines changed

docs/references/subcommands/analyze.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ We support the following archive formats:
128128

129129
In addition to the [standard flags](#specifying-fossa-project-details), the analyze command supports the following additional strategy flags:
130130

131-
| Name | Description |
132-
|-----------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
133-
| [`--detect-vendored`](./analyze/detect-vendored.md) | Enable the vendored source identification engine. For more information, see the [C and C++ overview](../strategies/languages/c-cpp/c-cpp.md). |
134-
| [`--detect-dynamic './some-binary`](./analyze/detect-dynamic.md) | Analyze the binary at the provided path for dynamically linked dependencies. For more information, see the [C and C++ overview](../strategies/languages/c-cpp/c-cpp.md). |
135-
| [`--static-only-analysis`](../strategies/README.md#static-and-dynamic-strategies) | Do not use third-party tools when analyzing projects. |
136-
| `--strict` | Enforces strict analysis to ensure the most accurate results for a strategy without resorting to fallbacks. |
131+
| Name | Description |
132+
|-----------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
133+
| [`--detect-vendored`](./analyze/detect-vendored.md) | Enable the vendored source identification engine. For more information, see the [C and C++ overview](../strategies/languages/c-cpp/c-cpp.md). |
134+
| [`--detect-dynamic './some-binary`](./analyze/detect-dynamic.md) | Analyze the binary at the provided path for dynamically linked dependencies. For more information, see the [C and C++ overview](../strategies/languages/c-cpp/c-cpp.md). |
135+
| [`--static-only-analysis`](../strategies/README.md#static-and-dynamic-strategies) | Do not use third-party tools when analyzing projects. |
136+
| `--strict` | Enforces strict analysis to ensure the most accurate results for a strategy by rejecting fallbacks. When ran with `--statitic-only-analysis`, the most optimal static strategy will be applied without fallbacks. |
137137

138138

139139
### Experimental Options

integration-test/Analysis/CarthageSpec.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Analysis.CarthageSpec (spec) where
55

66
import Analysis.FixtureExpectationUtils
77
import Analysis.FixtureUtils
8+
import App.Types (Mode (NonStrict))
89
import Path
910
import Strategy.Carthage qualified as Carthage
1011
import Test.Hspec
@@ -24,4 +25,4 @@ swiftQueue =
2425

2526
spec :: Spec
2627
spec = do
27-
testSuiteDepResultSummary swiftQueue CarthageProjectType (DependencyResultsSummary 1 1 0 1 Complete)
28+
testSuiteDepResultSummary NonStrict swiftQueue CarthageProjectType (DependencyResultsSummary 1 1 0 1 Complete)

integration-test/Analysis/ClojureSpec.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Analysis.ClojureSpec (spec) where
55

66
import Analysis.FixtureExpectationUtils
77
import Analysis.FixtureUtils
8+
import App.Types (Mode (NonStrict))
89
import Path
910
import Strategy.Leiningen qualified as Leiningen
1011
import Test.Hspec
@@ -39,5 +40,5 @@ ring =
3940

4041
spec :: Spec
4142
spec = do
42-
testSuiteDepResultSummary eastwood LeiningenProjectType (DependencyResultsSummary 10 7 3 1 Complete)
43-
testSuiteDepResultSummary ring LeiningenProjectType (DependencyResultsSummary 23 6 17 1 Complete)
43+
testSuiteDepResultSummary NonStrict eastwood LeiningenProjectType (DependencyResultsSummary 10 7 3 1 Complete)
44+
testSuiteDepResultSummary NonStrict ring LeiningenProjectType (DependencyResultsSummary 23 6 17 1 Complete)

integration-test/Analysis/CocoapodsSpec.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Analysis.CocoapodsSpec (spec) where
55

66
import Analysis.FixtureExpectationUtils
77
import Analysis.FixtureUtils
8+
import App.Types (Mode (..))
89
import Path
910
import Strategy.Cocoapods qualified as Cocoapods
1011
import Test.Hspec
@@ -36,5 +37,6 @@ sDWebImage =
3637

3738
spec :: Spec
3839
spec = do
39-
testSuiteDepResultSummary shadowsocksXNG CocoapodsProjectType (DependencyResultsSummary 7 6 2 1 Complete)
40-
testSuiteDepResultSummary sDWebImage CocoapodsProjectType (DependencyResultsSummary 4 4 0 1 Partial)
40+
testSuiteDepResultSummary NonStrict shadowsocksXNG CocoapodsProjectType (DependencyResultsSummary 7 6 2 1 Complete)
41+
testSuiteDepResultSummary Strict shadowsocksXNG CocoapodsProjectType (DependencyResultsSummary 7 6 2 1 Complete)
42+
testSuiteDepResultSummary NonStrict sDWebImage CocoapodsProjectType (DependencyResultsSummary 4 4 0 1 Partial)

integration-test/Analysis/ElixirSpec.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Analysis.ElixirSpec (spec) where
55

66
import Analysis.FixtureExpectationUtils
77
import Analysis.FixtureUtils
8+
import App.Types (Mode (NonStrict))
89
import Effect.Exec (AllowErr (Never), Command (Command))
910
import Path
1011
import Strategy.Mix qualified as Mix
@@ -42,4 +43,4 @@ absinthe =
4243

4344
spec :: Spec
4445
spec = do
45-
testSuiteDepResultSummary absinthe MixProjectType (DependencyResultsSummary 4 4 1 1 Complete)
46+
testSuiteDepResultSummary NonStrict absinthe MixProjectType (DependencyResultsSummary 4 4 1 1 Complete)

integration-test/Analysis/ErlangSpec.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Analysis.ErlangSpec (spec) where
55

66
import Analysis.FixtureExpectationUtils
77
import Analysis.FixtureUtils
8+
import App.Types (Mode (NonStrict))
89
import Path
910
import Strategy.Rebar3 qualified as Rebar3
1011
import Test.Hspec
@@ -39,5 +40,5 @@ emqx =
3940

4041
spec :: Spec
4142
spec = do
42-
testSuiteDepResultSummary cowboy Rebar3ProjectType (DependencyResultsSummary 2 2 0 1 Complete)
43-
testSuiteDepResultSummary emqx Rebar3ProjectType (DependencyResultsSummary 0 0 0 1 Complete)
43+
testSuiteDepResultSummary NonStrict cowboy Rebar3ProjectType (DependencyResultsSummary 2 2 0 1 Complete)
44+
testSuiteDepResultSummary NonStrict emqx Rebar3ProjectType (DependencyResultsSummary 0 0 0 1 Complete)

integration-test/Analysis/FixtureExpectationUtils.hs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Analysis.FixtureExpectationUtils (
1616

1717
import Analysis.FixtureUtils (AnalysisTestFixture (..), FixtureArtifact (..), getArtifact, performDiscoveryAndAnalyses)
1818
import App.Fossa.Analyze.Types (AnalyzeProject)
19+
import App.Types (Mode (..))
1920
import Control.Algebra (Has)
2021
import Control.Effect.Lift (Lift, sendIO)
2122
import Data.List (find)
@@ -51,12 +52,13 @@ summarize dr =
5152
-- | Performs discovery and analysis for all discovered project for provided analysis integration fixture.
5253
withAnalysisOf ::
5354
(Has (Lift IO) sig m, AnalyzeProject a, MonadFail m) =>
55+
Mode ->
5456
AnalysisTestFixture a ->
5557
(([(DiscoveredProject a, DependencyResults)], Path Abs Dir) -> m b) ->
5658
m ()
57-
withAnalysisOf testFixture runTest = do
59+
withAnalysisOf mode testFixture runTest = do
5860
extractedDir <- getArtifact (artifact testFixture)
59-
res <- performDiscoveryAndAnalyses extractedDir testFixture
61+
res <- performDiscoveryAndAnalyses extractedDir testFixture mode
6062
_ <- runTest (res, extractedDir </> (scopedDir . artifact $ testFixture))
6163
sendIO $ PIO.removeDirRecur extractedDir
6264

@@ -91,17 +93,17 @@ withProjectOfType result (projType, projPath) =
9193
find (\(dr, _) -> projectType dr == projType && projectPath dr == projPath) result
9294

9395
testSuiteHasSomeDepResults :: (AnalyzeProject a, Show a, Eq a) => AnalysisTestFixture a -> DiscoveredProjectType -> Spec
94-
testSuiteHasSomeDepResults fixture projType = aroundAll (withAnalysisOf fixture) $
96+
testSuiteHasSomeDepResults fixture projType = aroundAll (withAnalysisOf NonStrict fixture) $
9597
describe (toString $ testName fixture) $ do
9698
it "should find targets" $ \(result, extractedDir) ->
9799
expectProject (projType, extractedDir) result
98100

99101
it "should have some dependency results" $ \(result, extractedDir) ->
100102
isJust (getDepResultsOf result (projType, extractedDir)) `shouldBe` True
101103

102-
testSuiteDepResultSummary :: (AnalyzeProject a, Show a, Eq a) => AnalysisTestFixture a -> DiscoveredProjectType -> DependencyResultsSummary -> Spec
103-
testSuiteDepResultSummary fixture projType depResultSummary =
104-
aroundAll (withAnalysisOf fixture) $
104+
testSuiteDepResultSummary :: (AnalyzeProject a, Show a, Eq a) => Mode -> AnalysisTestFixture a -> DiscoveredProjectType -> DependencyResultsSummary -> Spec
105+
testSuiteDepResultSummary mode fixture projType depResultSummary =
106+
aroundAll (withAnalysisOf mode fixture) $
105107
describe (toString $ testName fixture) $ do
106108
it "should find targets" $ \(result, extractedDir) ->
107109
expectProject (projType, extractedDir) result

integration-test/Analysis/FixtureUtils.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ decorateCmdWith (NixEnv pkgs) cmd =
156156
-- --------------------------------
157157
-- Analysis fixture test runner
158158

159-
performDiscoveryAndAnalyses :: (Has (Lift IO) sig m, AnalyzeProject a, MonadFail m) => Path Abs Dir -> AnalysisTestFixture a -> m [(DiscoveredProject a, DependencyResults)]
160-
performDiscoveryAndAnalyses targetDir AnalysisTestFixture{..} = do
159+
performDiscoveryAndAnalyses :: (Has (Lift IO) sig m, AnalyzeProject a, MonadFail m) => Path Abs Dir -> AnalysisTestFixture a -> Mode -> m [(DiscoveredProject a, DependencyResults)]
160+
performDiscoveryAndAnalyses targetDir AnalysisTestFixture{..} mode = do
161161
-- Perform any project builds
162162
_ <- sendIO $ runCmd environment buildCmd
163163

164164
-- Perform discovery
165165
discoveryResult <- sendIO $ testRunner (discover targetDir) environment
166166
withResult discoveryResult $ \_ dps ->
167167
for dps $ \dp -> do
168-
analysisResult <- sendIO $ testRunner (ignoreDebug $ analyzeProject (projectBuildTargets dp) (projectData dp)) environment
168+
analysisResult <- sendIO $ testRunner (ignoreDebug $ runReader mode $ analyzeProject (projectBuildTargets dp) (projectData dp)) environment
169169
withResult analysisResult $ \_ dr -> pure (dp, dr)
170170
where
171171
runCmd :: FixtureEnvironment -> Maybe (Command) -> IO ()

integration-test/Analysis/GoSpec.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Analysis.GoSpec (spec) where
55

66
import Analysis.FixtureExpectationUtils
77
import Analysis.FixtureUtils
8+
import App.Types (Mode (NonStrict))
89
import Path
910
import Strategy.Gomodules qualified as Gomodules
1011
import Test.Hspec
@@ -27,7 +28,7 @@ vault =
2728

2829
testVault :: Spec
2930
testVault =
30-
aroundAll (withAnalysisOf vault) $ do
31+
aroundAll (withAnalysisOf NonStrict vault) $ do
3132
describe "vault" $ do
3233
it "should find targets" $ \(result, extractedDir) -> do
3334
expectProject (GomodProjectType, extractedDir) result

integration-test/Analysis/GradleSpec.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Analysis.FixtureUtils (
1212
FixtureArtifact (FixtureArtifact),
1313
FixtureEnvironment (NixEnv),
1414
)
15+
import App.Types (Mode (NonStrict))
1516
import Path (reldir)
1617
import Strategy.Gradle qualified as Gradle
1718
import Test.Hspec (Spec, aroundAll, describe, it, shouldBe)
@@ -46,15 +47,15 @@ gradleSettingsOnly =
4647

4748
testSpringBoot :: Spec
4849
testSpringBoot =
49-
aroundAll (withAnalysisOf springBoot) $ do
50+
aroundAll (withAnalysisOf NonStrict springBoot) $ do
5051
describe "gradle-java springboot" $ do
5152
it "should find targets" $ \(result, extractedDir) -> do
5253
expectProject (GradleProjectType, extractedDir) result
5354
length result `shouldBe` 1
5455

5556
testGradleSettingsOnly :: Spec
5657
testGradleSettingsOnly =
57-
aroundAll (withAnalysisOf gradleSettingsOnly) $ do
58+
aroundAll (withAnalysisOf NonStrict gradleSettingsOnly) $ do
5859
describe "gradle-java gradle settings only" $ do
5960
it "should find targets" $ \(result, extractedDir) -> do
6061
expectProject (GradleProjectType, extractedDir) result

0 commit comments

Comments
 (0)