Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Fixing doc gen call (#39) (#41)
Browse files Browse the repository at this point in the history
* fixing doc gen call

* adding a test for docs generation

* need to generate docs for source files only such that we can build the docs for muliple dlls without interferences

* forgot to check if the dictionary exists before clearning it in test
  • Loading branch information
bettinaheim committed Jul 13, 2019
1 parent 28ac533 commit bb0e8a4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/QsCompiler/Compiler/CompilationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ public CompilationLoader(SourceLoader loadSources, ReferenceLoader loadReference
this.CompilationStatus.Documentation = 0;
var docsFolder = Path.GetFullPath(String.IsNullOrWhiteSpace(this.Config.DocumentationOutputFolder) ? "." : this.Config.DocumentationOutputFolder);
void onDocException(Exception ex) => this.LogAndUpdate(ref this.CompilationStatus.Documentation, ex);
var (tree, sources) = (this.VerifiedCompilation?.SyntaxTree?.Values, this.VerifiedCompilation?.SyntaxTree?.Keys);
var docsGenerated = this.VerifiedCompilation != null && DocBuilder.Run(docsFolder, tree, sources, onException: onDocException);
var docsGenerated = this.VerifiedCompilation != null && DocBuilder.Run(docsFolder, this.VerifiedCompilation.SyntaxTree.Values, this.VerifiedCompilation.SourceFiles, onException: onDocException);
if (!docsGenerated) this.LogAndUpdate(ref this.CompilationStatus.Documentation, ErrorCode.DocGenerationFailed, Enumerable.Empty<string>());
}

Expand Down
57 changes: 42 additions & 15 deletions src/QsCompiler/Tests.Compiler/CommandLineTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@ let ``valid snippet`` () =
[<Fact>]
let ``invalid snippet`` () =
[|
@"-s"
@"let a = "
"-s"
"let a = "
|]
|> testSnippet ReturnCode.COMPILATION_ERRORS


[<Fact>]
let ``one valid file`` () =
[|
@"-i"
"-i"
("TestFiles","test-00.qs") |> Path.Combine
@"-v"
"-v"
|]
|> testInput ReturnCode.SUCCESS

[<Fact>]
let ``multiple valid file`` () =
[|
@"--input"
"--input"
("TestFiles","test-00.qs") |> Path.Combine
("TestFiles","test-01.qs") |> Path.Combine
|]
Expand All @@ -74,7 +74,7 @@ let ``multiple valid file`` () =
[<Fact>]
let ``one invalid file`` () =
[|
@"-i"
"-i"
("TestFiles","test-02.qs") |> Path.Combine
|]
|> testInput ReturnCode.COMPILATION_ERRORS
Expand All @@ -83,7 +83,7 @@ let ``one invalid file`` () =
[<Fact>]
let ``mixed files`` () =
[|
@"-i"
"-i"
("TestFiles","test-01.qs") |> Path.Combine
("TestFiles","test-02.qs") |> Path.Combine
|]
Expand All @@ -93,13 +93,13 @@ let ``mixed files`` () =
[<Fact>]
let ``missing file`` () =
[|
@"-i"
"-i"
("TestFiles","foo-00.qs") |> Path.Combine
|]
|> testInput ReturnCode.UNRESOLVED_FILES

[|
@"-i"
"-i"
("TestFiles","test-01.qs") |> Path.Combine
("TestFiles","foo-00.qs") |> Path.Combine
|]
Expand All @@ -109,9 +109,9 @@ let ``missing file`` () =
[<Fact>]
let ``invalid argument`` () =
[|
@"-i"
"-i"
("TestFiles","test-00.qs") |> Path.Combine
@"--foo"
"--foo"
|]
|> testInput ReturnCode.INVALID_ARGUMENTS

Expand All @@ -120,7 +120,7 @@ let ``invalid argument`` () =
let ``missing verb`` () =
let args =
[|
@"-i"
"-i"
("TestFiles","test-00.qs") |> Path.Combine
|]
let result = Program.Main args
Expand All @@ -131,8 +131,8 @@ let ``missing verb`` () =
let ``invalid verb`` () =
let args =
[|
@"foo"
@"-i"
"foo"
"-i"
("TestFiles","test-00.qs") |> Path.Combine
|]
let result = Program.Main args
Expand All @@ -143,7 +143,7 @@ let ``invalid verb`` () =
let ``diagnose outputs`` () =
let args =
[|
@"-i"
"-i"
("TestFiles","test-00.qs") |> Path.Combine
"--tree"
"--tokenization"
Expand All @@ -153,6 +153,33 @@ let ``diagnose outputs`` () =
let result = Program.Main args
Assert.Equal(ReturnCode.INVALID_ARGUMENTS, result)


[<Fact>]
let ``generate docs`` () =
let docsFolder = ("TestFiles", "docs.Out") |> Path.Combine
if (Directory.Exists docsFolder) then
for file in Directory.GetFiles docsFolder do
File.Delete file

let toc = Path.Combine (docsFolder, "toc.yml")
let nsDoc = Path.Combine (docsFolder, "Compiler.Tests.yml")
let opDoc = Path.Combine (docsFolder, "compiler.tests.test01.yml")
let existsAndNotEmpty fileName = fileName |> File.Exists && not (File.ReadAllText fileName |> String.IsNullOrWhiteSpace)
let args =
[|
"build"
"--input"
("TestFiles","test-01.qs") |> Path.Combine
"--doc"
docsFolder
|]

let result = Program.Main args
Assert.Equal(ReturnCode.SUCCESS, result)
Assert.True (existsAndNotEmpty toc)
Assert.True (existsAndNotEmpty nsDoc)
Assert.True (existsAndNotEmpty opDoc)


[<Fact>]
let ``find path relative`` () =
Expand Down
4 changes: 3 additions & 1 deletion src/QsCompiler/Tests.Compiler/TestFiles/test-01.qs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@

namespace Compiler.Tests
{
operation test01() : () { body intrinsic; }
/// # Summary
/// Test operation.
operation Test01() : Unit { body intrinsic; }
}

0 comments on commit bb0e8a4

Please sign in to comment.