@@ -518,7 +518,8 @@ void main() {
518
518
"kDouble": 1.1,
519
519
"name": "denghaizhu",
520
520
"title": "this is title from config json file",
521
- "nullValue": null
521
+ "nullValue": null,
522
+ "containEqual": "sfadsfv=432f"
522
523
}
523
524
'''
524
525
);
@@ -549,6 +550,7 @@ void main() {
549
550
'name=denghaizhu' ,
550
551
'title=this is title from config json file' ,
551
552
'nullValue=null' ,
553
+ 'containEqual=sfadsfv=432f' ,
552
554
'body=this is body from config json file' ,
553
555
]),
554
556
);
@@ -557,6 +559,155 @@ void main() {
557
559
ProcessManager : () => FakeProcessManager .any (),
558
560
});
559
561
562
+ testUsingContext ('--dart-define-from-file correctly parses a valid env file' , () async {
563
+ globals.fs
564
+ .file (globals.fs.path.join ('lib' , 'main.dart' ))
565
+ .createSync (recursive: true );
566
+ globals.fs.file ('pubspec.yaml' ).createSync ();
567
+ globals.fs.file ('.packages' ).createSync ();
568
+ await globals.fs.file ('.env' ).writeAsString ('''
569
+ # comment
570
+ kInt=1
571
+ kDouble=1.1 # should be double
572
+
573
+ name=piotrfleury
574
+ title=this is title from config env file
575
+ empty=
576
+
577
+ doubleQuotes="double quotes 'value'#=" # double quotes
578
+ singleQuotes='single quotes "value"#=' # single quotes
579
+ backQuotes=`back quotes "value" '#=` # back quotes
580
+
581
+ hashString="some-#-hash-string-value"
582
+
583
+ # Play around with spaces around the equals sign.
584
+ spaceBeforeEqual =value
585
+ spaceAroundEqual = value
586
+ spaceAfterEqual= value
587
+
588
+ ''' );
589
+ await globals.fs.file ('.env2' ).writeAsString ('''
590
+ # second comment
591
+
592
+ body=this is body from config env file
593
+ ''' );
594
+ final CommandRunner <void > runner =
595
+ createTestCommandRunner (BuildBundleCommand (
596
+ logger: BufferLogger .test (),
597
+ ));
598
+
599
+ await runner.run (< String > [
600
+ 'bundle' ,
601
+ '--no-pub' ,
602
+ '--dart-define-from-file=.env' ,
603
+ '--dart-define-from-file=.env2' ,
604
+ ]);
605
+ }, overrides: < Type , Generator > {
606
+ BuildSystem : () => TestBuildSystem .all (BuildResult (success: true ),
607
+ (Target target, Environment environment) {
608
+ expect (
609
+ _decodeDartDefines (environment),
610
+ containsAllInOrder (const < String > [
611
+ 'kInt=1' ,
612
+ 'kDouble=1.1' ,
613
+ 'name=piotrfleury' ,
614
+ 'title=this is title from config env file' ,
615
+ 'empty=' ,
616
+ "doubleQuotes=double quotes 'value'#=" ,
617
+ 'singleQuotes=single quotes "value"#=' ,
618
+ 'backQuotes=back quotes "value" \' #=' ,
619
+ 'hashString=some-#-hash-string-value' ,
620
+ 'spaceBeforeEqual=value' ,
621
+ 'spaceAroundEqual=value' ,
622
+ 'spaceAfterEqual=value' ,
623
+ 'body=this is body from config env file'
624
+ ]),
625
+ );
626
+ }),
627
+ FileSystem : fsFactory,
628
+ ProcessManager : () => FakeProcessManager .any (),
629
+ });
630
+
631
+ testUsingContext ('--dart-define-from-file option env file throws a ToolExit when .env file contains a multiline value' , () async {
632
+ globals.fs
633
+ .file (globals.fs.path.join ('lib' , 'main.dart' ))
634
+ .createSync (recursive: true );
635
+ globals.fs.file ('pubspec.yaml' ).createSync ();
636
+ globals.fs.file ('.packages' ).createSync ();
637
+ await globals.fs.file ('.env' ).writeAsString ('''
638
+ # single line value
639
+ name=piotrfleury
640
+
641
+ # multi-line value
642
+ multiline = """ Welcome to .env demo
643
+ a simple counter app with .env file support
644
+ for more info, check out the README.md file
645
+ Thanks! """ # This is the welcome message that will be displayed on the counter app
646
+
647
+ ''' );
648
+ final CommandRunner <void > runner =
649
+ createTestCommandRunner (BuildBundleCommand (
650
+ logger: BufferLogger .test (),
651
+ ));
652
+
653
+ expect (() => runner.run (< String > [
654
+ 'bundle' ,
655
+ '--no-pub' ,
656
+ '--dart-define-from-file=.env' ,
657
+ ]), throwsToolExit (message: 'Multi-line value is not supported: multiline = """ Welcome to .env demo' ));
658
+ }, overrides: < Type , Generator > {
659
+ BuildSystem : () => TestBuildSystem .all (BuildResult (success: true )),
660
+ FileSystem : fsFactory,
661
+ ProcessManager : () => FakeProcessManager .any (),
662
+ });
663
+
664
+ testUsingContext ('--dart-define-from-file option works with mixed file formats' ,
665
+ () async {
666
+ globals.fs
667
+ .file (globals.fs.path.join ('lib' , 'main.dart' ))
668
+ .createSync (recursive: true );
669
+ globals.fs.file ('pubspec.yaml' ).createSync ();
670
+ globals.fs.file ('.packages' ).createSync ();
671
+ await globals.fs.file ('.env' ).writeAsString ('''
672
+ kInt=1
673
+ kDouble=1.1
674
+ name=piotrfleury
675
+ title=this is title from config env file
676
+ ''' );
677
+ await globals.fs.file ('config.json' ).writeAsString ('''
678
+ {
679
+ "body": "this is body from config json file"
680
+ }
681
+ ''' );
682
+ final CommandRunner <void > runner =
683
+ createTestCommandRunner (BuildBundleCommand (
684
+ logger: BufferLogger .test (),
685
+ ));
686
+
687
+ await runner.run (< String > [
688
+ 'bundle' ,
689
+ '--no-pub' ,
690
+ '--dart-define-from-file=.env' ,
691
+ '--dart-define-from-file=config.json' ,
692
+ ]);
693
+ }, overrides: < Type , Generator > {
694
+ BuildSystem : () => TestBuildSystem .all (BuildResult (success: true ),
695
+ (Target target, Environment environment) {
696
+ expect (
697
+ _decodeDartDefines (environment),
698
+ containsAllInOrder (const < String > [
699
+ 'kInt=1' ,
700
+ 'kDouble=1.1' ,
701
+ 'name=piotrfleury' ,
702
+ 'title=this is title from config env file' ,
703
+ 'body=this is body from config json file' ,
704
+ ]),
705
+ );
706
+ }),
707
+ FileSystem : fsFactory,
708
+ ProcessManager : () => FakeProcessManager .any (),
709
+ });
710
+
560
711
testUsingContext ('test --dart-define-from-file option if conflict' , () async {
561
712
globals.fs.file (globals.fs.path.join ('lib' , 'main.dart' )).createSync (recursive: true );
562
713
globals.fs.file ('pubspec.yaml' ).createSync ();
0 commit comments